-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.mdc
More file actions
79 lines (69 loc) · 2.12 KB
/
python.mdc
File metadata and controls
79 lines (69 loc) · 2.12 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
description:
globs: **/*.py
alwaysApply: false
---
---
description: Python best practices and patterns for modern software development
globs: **/*.py, src/**/*.py, tests/**/*.py
---
# Python Best Practices
## Project Structure
- Use src-layout with `src/your_package_name/`
- Place tests in `tests/` directory and keep it flat
- Keep configuration in `config/` or as environment variables
- Store requirements in `pyproject.toml`
- Use `templates/` for Jinja2 templates
## Code Style
- Follow Ruff code formatting
- Use isort for import sorting
- Follow PEP 8 naming conventions:
- snake_case for functions and variables
- PascalCase for classes
- UPPER_CASE for constants
- Maximum line length of 88 characters (Black default)
- Use absolute imports over relative imports
## Type Hints
- Use type hints for all function parameters and returns
- Import types from `typing` module
- Use `Optional[Type]` instead of `Type | None`
- Use `TypeVar` for generic types
- Define custom types in `types.py`
- Use `Protocol` for duck typing
## Testing
- Use pytest for testing
- Implement proper fixtures
- Use proper mocking with pytest-mock
- Test all error scenarios
## Performance
- Use proper connection pooling when needed
- Use background tasks for heavy operations
- Monitor application performance
## Error Handling
- Create custom exception classes
- Use proper try-except blocks
- Implement proper logging
- Return proper error responses
- Handle edge cases properly
- Use proper error messages
## Documentation
- Use Google-style docstrings
- Document all public APIs
- Keep README.md updated
- Use proper inline comments
- Document using markdown in `docs` directory
## Development Workflow
- Follow TDD methology and write acceptence tests
- Use pytest extensively to test your code
- Use virtual environments (venv)
- Use proper Git workflow
- Follow semantic versioning
- Use proper CI/CD practices
- Implement proper logging
## Dependencies
- Pin dependency versions
- Separate dev dependencies
- Use proper package versions
- Regularly update dependencies
- Check for security vulnerabilities
- Use uv for venv and dependency management