|
| 1 | +### 1. Avoid Breaking Changes (Stable Public Interfaces) |
| 2 | + |
| 3 | +* Carefully preserve **function signatures**, argument positions, and names for any exported/public methods. |
| 4 | +* Be cautious when **renaming**, **removing**, or **reordering** arguments — even small changes can break downstream consumers. |
| 5 | +* Use keyword-only arguments or clearly mark experimental features to isolate unstable APIs. |
| 6 | + |
| 7 | +Bad: |
| 8 | + |
| 9 | +```python |
| 10 | +def get_user(id, verbose=False): # Changed from `user_id` |
| 11 | +``` |
| 12 | + |
| 13 | +Good: |
| 14 | + |
| 15 | +```python |
| 16 | +def get_user(user_id: str, verbose: bool = False): # Maintains stable interface |
| 17 | +``` |
| 18 | + |
| 19 | +🧠 *Ask yourself:* “Would this change break someone's code if they used it last week?” |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +### 2. Simplify Code and Use Clear Variable Names |
| 24 | + |
| 25 | +* Prefer descriptive, **self-explanatory variable names**. Avoid overly short or cryptic identifiers. |
| 26 | +* Break up overly long or deeply nested functions for **readability and maintainability**. |
| 27 | +* Avoid unnecessary abstraction or premature optimization. |
| 28 | +* All generated Python code must include type hints. |
| 29 | + |
| 30 | +Bad: |
| 31 | + |
| 32 | +```python |
| 33 | +def p(u, d): |
| 34 | + return [x for x in u if x not in d] |
| 35 | +``` |
| 36 | + |
| 37 | +Good: |
| 38 | + |
| 39 | +```python |
| 40 | +def filter_unknown_users(users: List[str], known_users: Set[str]) -> List[str]: |
| 41 | + return [user for user in users if user not in known_users] |
| 42 | +``` |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +### 3. Ensure Unit Tests Cover New and Updated Functionality |
| 47 | + |
| 48 | +* Every new feature or bugfix should be **covered by a unit test**. |
| 49 | +* Test edge cases and failure conditions. |
| 50 | +* Use `pytest`, `unittest`, or the project’s existing framework consistently. |
| 51 | + |
| 52 | +Checklist: |
| 53 | + |
| 54 | +* [ ] Does the test suite fail if your new logic is broken? |
| 55 | +* [ ] Are all expected behaviors exercised (happy path, invalid input, etc)? |
| 56 | +* [ ] Do tests use fixtures or mocks where needed? |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +### 4. Look for Suspicious or Risky Code |
| 61 | + |
| 62 | +* Watch out for: |
| 63 | + |
| 64 | + * Use of `eval()`, `exec()`, or `pickle` on user-controlled input. |
| 65 | + * Silent failure modes (`except: pass`). |
| 66 | + * Unreachable code or commented-out blocks. |
| 67 | + * Race conditions or resource leaks (file handles, sockets, threads). |
| 68 | + |
| 69 | +Bad: |
| 70 | + |
| 71 | +```python |
| 72 | +def load_config(path): |
| 73 | + with open(path) as f: |
| 74 | + return eval(f.read()) # ⚠️ Never eval config |
| 75 | +``` |
| 76 | + |
| 77 | +Good: |
| 78 | + |
| 79 | +```python |
| 80 | +import json |
| 81 | + |
| 82 | +def load_config(path: str) -> dict: |
| 83 | + with open(path) as f: |
| 84 | + return json.load(f) |
| 85 | +``` |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +### 5. Use Google-Style Docstrings (with Args section) |
| 90 | + |
| 91 | +* All public functions should include a **Google-style docstring**. |
| 92 | +* Include an `Args:` section where relevant. |
| 93 | +* Types should NOT be written in the docstring — use type hints instead. |
| 94 | + |
| 95 | +Bad: |
| 96 | + |
| 97 | +```python |
| 98 | +def send_email(to, msg): |
| 99 | + """Send an email to a recipient.""" |
| 100 | +``` |
| 101 | + |
| 102 | +Good: |
| 103 | + |
| 104 | +```python |
| 105 | +def send_email(to: str, msg: str) -> None: |
| 106 | + """ |
| 107 | + Sends an email to a recipient. |
| 108 | +
|
| 109 | + Args: |
| 110 | + to: The email address of the recipient. |
| 111 | + msg: The message body. |
| 112 | + """ |
| 113 | +``` |
| 114 | + |
| 115 | +📌 *Tip:* Keep descriptions concise but clear. Only document return values if non-obvious. |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +### 6. Propose Better Designs When Applicable |
| 120 | + |
| 121 | +* If there's a **cleaner**, **more scalable**, or **simpler** design, highlight it. |
| 122 | +* Suggest improvements, even if they require some refactoring — especially if the new code would: |
| 123 | + |
| 124 | + * Reduce duplication |
| 125 | + * Make unit testing easier |
| 126 | + * Improve separation of concerns |
| 127 | + * Add clarity without adding complexity |
| 128 | + |
| 129 | +Instead of: |
| 130 | + |
| 131 | +```python |
| 132 | +def save(data, db_conn): |
| 133 | + # manually serializes fields |
| 134 | +``` |
| 135 | + |
| 136 | +You might suggest: |
| 137 | + |
| 138 | +```python |
| 139 | +# Suggest using dataclasses or Pydantic for automatic serialization and validation |
| 140 | +``` |
| 141 | + |
| 142 | +### 7. Misc |
| 143 | + |
| 144 | +* When suggesting package installation commands, use `uv pip install` as this project uses `uv`. |
| 145 | +* When creating tools for agents, use the @tool decorator from langchain_core.tools. The tool's docstring serves as its functional description for the agent. |
| 146 | +* Avoid suggesting deprecated components, such as the legacy LLMChain. |
| 147 | +* We use Conventional Commits format for pull request titles. Example PR titles: |
| 148 | + * feat(core): add multi‐tenant support |
| 149 | + * fix(cli): resolve flag parsing error |
| 150 | + * docs: update API usage examples |
| 151 | + * docs(openai): update API usage examples |
0 commit comments