-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpython.cursorrules
More file actions
29 lines (24 loc) · 1.07 KB
/
python.cursorrules
File metadata and controls
29 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Python Rules
## Style & Structure
- Use type hints for all function signatures and return types
- Prefer f-strings over .format() or % formatting
- Use pathlib instead of os.path for file operations
- Prefer list/dict/set comprehensions over map/filter when readable
- Use dataclasses or Pydantic models instead of plain dicts for structured data
## Error Handling
- Use specific exception types, never bare except
- Use contextlib.suppress() for expected exceptions
- Return early to avoid deep nesting
## Imports
- Group imports: stdlib, third-party, local (separated by blank lines)
- Use absolute imports over relative imports
- Never use wildcard imports (from x import *)
## Functions
- Keep functions under 30 lines — extract helpers
- Use *args and **kwargs sparingly and document when used
- Prefer returning values over modifying mutable arguments
- Use generators for large sequences (yield over building lists)
## Testing
- Use pytest over unittest
- Name tests descriptively: test_<function>_<scenario>_<expected>
- Use fixtures for shared setup, parametrize for multiple cases