Best Practices
Project conventions for all new and modified code live in
.cursor/rules/python_best_practices.mdc (with peer files for
dependency_management, documentation, environment_best_practices,
git_workflow, pull_request, and security). That file is the
authoritative standard; this page lists the rules that come up most often.
Code style
Maximum line length: 100 characters (enforced by Ruff).
Naming:
lowercase_with_underscoresfor functions and local variables,TitleCasefor classes,ALL_CAPS_WITH_UNDERSCORESfor module-level constants. Prefix non-public names with a single underscore.Type-annotate every function parameter and return value, including
-> None. Use modernlist[str],dict[str, int],X | Nonesyntax.Keep modules under 1000 lines. Split larger modules into a package.
Do not introduce backwards-compatibility shims unless explicitly requested; change the code instead.
Linting and typing
Run
ruff check src testsandruff format --check src testson the full codebase after changes.Run
mypy src testsand fix every error. Do not add module-level# mypy: ignore-errorsor globalexcludeentries. A line-level# type: ignore[error-code]is acceptable only with a brief justification.
Testing
Use
pytestwithpytest-xdist; the canonical command ispytest -n auto --dist=loadfile(the--dist=loadfileflag is required because PyQt6 workers crash under default xdist scheduling).Annotate test function parameters and return types; return
-> None.One assertion per condition (no
andin assertions). When testing exceptions, usepytest.raisesas a context manager and assert on the exception message content viamatch=.Target at least 90 % line coverage over the full suite.
Documentation
Every module, class, function, and method has a docstring written in Google style with
Parameters:,Returns:, andRaises:as needed. Wrap docstring text to 90 characters.Do not use smart quotes, em-dashes, or arrows in
.pyfiles (they are fine in.rstand.md).Update docstrings when the associated code changes, and remove them when the code is removed.
After a code change, run
sphinx-build -W -b html docs docs/_buildand fix every warning.