| applyTo | python_files/** |
|---|---|
| description | Guide for running and fixing Python quality checks (Ruff and Pyright) that run in CI |
Run the same Python quality checks that run in CI. All checks target python_files/ and use config from python_files/pyproject.toml.
npm run check-python # Run both Ruff and Pyright
npm run check-python:ruff # Linting and formatting only
npm run check-python:pyright # Type checking onlyAuto-fix most issues:
cd python_files
python -m ruff check . --fix
python -m ruff format
npm run check-python:ruff # VerifyManual fixes:
- Ruff shows file, line number, rule code (e.g.,
F841), and description - Open the file, read the error, fix the code
- Common: line length (100 char max), import sorting, unused variables
Common patterns and fixes:
- Undefined variable/import: Add the missing import
- Type mismatch: Correct the type or add type annotations
- Missing return type: Add
-> ReturnTypeto function signaturesdef my_function() -> str: # Add return type return "result"
Verify:
npm run check-python:pyright- Ruff: Line length 100, Python 3.9+, 40+ rule families (flake8, isort, pyupgrade, etc.)
- Pyright: Version 1.1.308 (or whatever is found in the environment), ignores
lib/and 15+ legacy files - Config:
python_files/pyproject.tomlsections[tool.ruff]and[tool.pyright]
"Module not found" in Pyright: Install dependencies
python -m pip install --upgrade -r build/test-requirements.txt
nox --session install_python_libsImport order errors: Auto-fix with ruff check . --fix
Type errors in ignored files: Legacy files in pyproject.toml ignore list—fix if working on them
- Always run
npm run check-pythonbefore pushing to catch CI failures early (1) - Use
ruff check . --fixto auto-fix most linting issues before manual review (1) - Pyright version must match CI (1.1.308) to avoid inconsistent results between local and CI runs (1)