Python
General
- •For complex python projects, use OOP and Dependency Injection pattern.
- •Use
uv runto execute Python scripts. - •Prefer
black+ruffdefaults unless the project specifies otherwise. - •Use absolute imports; avoid wildcard imports.
- •Raise specific exceptions; avoid bare
except. - •Prefer
pytestfor tests. - •Document public functions and classes with docstrings.
Logging
- •Use the
loggingmodule with percent formatting (e.g.logger.info("Processing %s items", count)). - •Put a module-level logger at the top of each file (e.g.
logger = logging.getLogger(__name__)). - •Use logging formats that include relative file path and line number so logs are clickable in VS Code (e.g.
%(filename)s:%(lineno)d).
Type Hints
- •Use type hints for parameters, return types, and non-intuitive variables.
- •Prefer modern
typing/collections.abctypes; avoidAnyunless justified.