python-best-practiceslisted
Install: claude install-skill vitoriarntrindade/pocketledger-openspec
# Python best practices
The tools decide most of this. `ruff` settles formatting, imports, line length
and lint rules; `mypy` settles types. Run them rather than reasoning about
them:
```
make fast formatting, lint, types — the edit loop
make fix apply safe autofixes first, then check
make quality the full gate, including tests and coverage
```
**Never satisfy a check by disabling it.** A blanket `# noqa`, a widened
`ignore` list or a deleted assertion converts a real signal into a false one.
If a rule genuinely does not fit this project, change the rule in
`pyproject.toml` as a deliberate, justified decision — not inline, silently.
What follows is the part tools cannot check.
## The standards that are not negotiable
**Type hints on every signature**, parameters and return alike. Modern syntax,
since this project targets Python 3.12:
```python
def get_owned_category(db: Session, user: User, category_id: int) -> Category:
```
Use `X | None`, `list[X]`, `dict[str, X]`. Not `Optional[X]`, `List[X]`,
`Dict[str, X]` — those are the pre-3.10 spelling and only add noise now.
**78-character lines.** Break with parentheses, never backslashes. The
formatter does most of it; you break the long strings and comments it cannot.
**Google-style docstrings** on public functions, classes and modules.
**Exception chaining.** Always `raise NewError(...) from err`. Dropping the
cause discards the traceback that explains the failure:
```python
try:
user_id = decode_acc