Skip to content

Commit 5ee8462

Browse files
committed
updates doc rules
1 parent ad55afd commit 5ee8462

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed
Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,73 @@
11
---
22
applyTo: '**/*.py'
33
---
4-
Provide project context and coding guidelines that AI should follow when generating code, answering questions, or reviewing changes.
54

65
## 🛠️Coding Instructions for Python in This Repository
76

87
Follow these rules **strictly** when generating Python code:
98

10-
### 1. Python Version
9+
### Python Version
1110

1211
* Use Python 3.11: Ensure all code uses features and syntax compatible with Python 3.11.
1312

14-
### 2. **Type Annotations**
13+
### Type Annotations
1514

1615
* Always use full type annotations for all functions and class attributes.
1716
***Exception**: Do **not** add return type annotations in `test_*` functions.
1817

19-
### 3. **Code Style & Formatting**
18+
### Documentation with Annotated Types
19+
20+
* Use `annotated_types.doc()` for parameter and return type documentation instead of traditional docstring Args/Returns sections
21+
* **Apply documentation only for non-obvious parameters/returns**:
22+
- Document complex behaviors that can't be deduced from parameter name and type
23+
- Document validation rules, side effects, or special handling
24+
- Skip documentation for self-explanatory parameters (e.g., `engine: AsyncEngine`, `product_name: ProductName`)
25+
* **Import**: Always add `from annotated_types import doc` when using documentation annotations
26+
27+
**Examples:**
28+
```python
29+
from typing import Annotated
30+
from annotated_types import doc
31+
32+
async def process_users(
33+
engine: AsyncEngine, # No doc needed - self-explanatory
34+
filter_statuses: Annotated[
35+
list[Status] | None,
36+
doc("Only returns users with these statuses")
37+
] = None,
38+
limit: int = 50, # No doc needed - obvious
39+
) -> Annotated[
40+
tuple[list[dict], int],
41+
doc("(user records, total count)")
42+
]:
43+
"""Process users with filtering.
44+
45+
Raises:
46+
ValueError: If no filters provided
47+
"""
48+
```
49+
50+
* **Docstring conventions**:
51+
- Keep docstrings **concise**, focusing on overall function purpose
52+
- Include `Raises:` section for exceptions
53+
- Avoid repeating information already captured in type annotations
54+
- Most information should be deducible from function name, parameter names, types, and annotations
55+
56+
### Code Style & Formatting
2057

2158
* Follow [Python Coding Conventions](../../docs/coding-conventions.md) **strictly**.
2259
* Format code with `black` and `ruff`.
2360
* Lint code with `ruff` and `pylint`.
2461

25-
### 4. **Library Compatibility**
62+
### Library Compatibility
2663

2764
Ensure compatibility with the following library versions:
2865

2966
* `sqlalchemy` ≥ 2.x
3067
* `pydantic` ≥ 2.x
3168
* `fastapi` ≥ 0.100
3269

33-
34-
### 5. **Code Practices**
70+
### Code Practices
3571

3672
* Use `f-string` formatting for all string interpolation except for logging message strings.
3773
* Use **relative imports** within the same package/module.
@@ -40,13 +76,12 @@ Ensure compatibility with the following library versions:
4076
* Place **all imports at the top** of the file.
4177
* Document functions when the code is not self-explanatory or if asked explicitly.
4278

43-
44-
### 6. **JSON Serialization**
79+
### JSON Serialization
4580

4681
* Prefer `json_dumps` / `json_loads` from `common_library.json_serialization` instead of the built-in `json.dumps` / `json.loads`.
4782
* When using Pydantic models, prefer methods like `model.model_dump_json()` for serialization.
4883

49-
### 7. **aiohttp Framework**
84+
### aiohttp Framework
5085

5186
* **Application Keys**: Always use `web.AppKey` for type-safe application storage instead of string keys
5287
- Define keys with specific types: `APP_MY_KEY: Final = web.AppKey("APP_MY_KEY", MySpecificType)`
@@ -58,6 +93,6 @@ Ensure compatibility with the following library versions:
5893
* **Error Handling**: Use the established exception handling decorators and patterns
5994
* **Route Definitions**: Use `web.RouteTableDef()` and organize routes logically within modules
6095

61-
### 8. **Running tests**
96+
### Running tests
6297
* Use `--keep-docker-up` flag when testing to keep docker containers up between sessions.
6398
* Always activate the python virtual environment before running pytest.

0 commit comments

Comments
 (0)