Files
ai-training/.cursor/rules/python.mdc
T
Oleksandr Bezdieniezhnykh cd04f282d0 Enhance coding guidelines in .cursor/rules/coderule.mdc and .cursor/rules/python.mdc
- Added a guideline to place all source code under the `src/` directory in `coderule.mdc`.
- Removed the outdated guideline regarding the `src/` layout in `python.mdc` to streamline project structure.

These updates improve project organization and maintainability by clarifying the structure for source code and project files.
2026-03-28 16:18:03 +02:00

17 lines
889 B
Plaintext

---
description: "Python coding conventions: PEP 8, type hints, pydantic, pytest, async patterns, project structure"
globs: ["**/*.py", "**/pyproject.toml", "**/requirements*.txt"]
---
# Python
- Follow PEP 8: snake_case for functions/variables, PascalCase for classes, UPPER_CASE for constants
- Use type hints on all function signatures; validate with `mypy` or `pyright`
- Use `pydantic` for data validation and serialization
- Import order: stdlib -> third-party -> local; use absolute imports
- Use context managers (`with`) for resource management
- Catch specific exceptions, never bare `except:`; use custom exception classes
- Use `async`/`await` with `asyncio` for I/O-bound concurrency
- Use `pytest` for testing (not `unittest`); fixtures for setup/teardown
- Use virtual environments (`venv` or `poetry`); pin dependencies
- Format with `black`; lint with `ruff` or `flake8`