Skip to content

python

Python sources: lint, layout, strict types, docstrings that match their signatures, and no unused code or dependencies. Guide: Python.

A scope has a file extension .py, or a file with a shebang for python, or project files pyproject.toml, requirements*.txt, or Pipfile. Also when django, fastapi, flask, machine-learning, pyjwt, or pytest requires it.

Lints every Python file with the Ruff rules for the level, security rules included.

Runs at the commit stage. gspot check --fix fixes what it can.

Undefined names, unused code, and insecure calls fail at run time or open a security hole, and a reader misses them.

Run the fix: command that the report prints for the rules that fix themselves.

eval(user_input) reports S307. Parse the input instead, and allow only known operations.

gspot ignore python/ruff --paths "<path>" --reason "<why>"
gspot ignore python/ruff --rule <rule> --reason "<why>"

To silence one place, write a comment such as:

import plugins # noqa: F401 # reason: the module registers its plugins on import

Checks the layout of every Python file against the Ruff formatter.

Runs at the commit stage. gspot check --fix fixes what it can.

One layout everywhere keeps a diff about the change.

Run the fix: command that the report prints.

value=1 differs from the Ruff output. Run gspot check --fix to get value = 1.

gspot ignore python/ruff-format --paths "<path>" --reason "<why>"

Type checks the project. At level all, it also requires annotations.

Runs at the push stage, once per scope, and needs the Python environment of the project.

The type checker finds a wrong type before a user hits the crash.

Fix the type, or narrow it where the value arrives.

count: int = "one" reports an incompatible type. Assign a number, such as count: int = 1, or change the annotation to str.

gspot ignore python/basedpyright --paths "<path>" --reason "<why>"
gspot ignore python/basedpyright --rule <rule> --reason "<why>"

To silence one place, write a comment such as:

value = payload['key'] # type: ignore[index] # reason: the payload is checked above

Checks that each docstring names the arguments, return value, and exceptions of its function. At level all, a one-line docstring names the arguments too.

Runs at the commit stage.

A docstring that contradicts the signature misleads more than none, because people trust it.

Bring the docstring in line with the signature.

A docstring that documents name for a function that takes path reports a mismatch. Document path instead.

gspot ignore python/pydoclint --paths "<path>" --reason "<why>"
gspot ignore python/pydoclint --rule <rule> --reason "<why>"

Compares the imports of the project with the dependencies it declares: missing, unused, and transitive ones.

Runs at the push stage, once per scope, with uv, and needs the Python environment of the project.

An import that works through somebody else’s dependency breaks the day they drop it.

Declare the dependency, or remove the one nothing imports.

An import of a third-party package missing from the project dependencies reports a finding. Declare the package and update the lockfile, or remove the import.

gspot ignore python/deptry --paths "<path>" --reason "<why>"
gspot ignore python/deptry --rule <rule> --reason "<why>"

Finds functions, classes, methods, attributes, and properties that no Python file of the scope uses, and code that never runs.

Runs at the push stage, only at the all level, once per scope.

Code that nothing calls still costs a reader time and still has to compile and pass review.

Delete the unused definition or the unreachable code.

A function that no Python file of the scope calls reports unused-function. Delete it. A file of hooks that a framework calls by name gets an ignore for its path.

Rule What it checks What to do
unreachable-code No code follows a return, raise, break, or continue in the same block. Remove the lines after that statement, or move them before it.
unused-attribute Code reads each attribute that it sets. Delete the attribute. When code reads it by name, ignore the finding with a reason.
unused-class Code uses each class that it defines. Delete the class. When code loads it by name, ignore the finding with a reason.
unused-function Code calls each function that it defines. Delete the function. When code calls it by name, ignore the finding with a reason.
unused-method Code calls each method that a class defines. Delete the method. When code calls it by name, ignore the finding with a reason.
unused-property Code reads each property that a class defines. Delete the property. When code reads it by name, ignore the finding with a reason.
gspot ignore python/vulture --paths "<path>" --reason "<why>"
gspot ignore python/vulture --rule unreachable-code --reason "<why>"

Checks the code line count of each Python function against limits.python.max_function_lines.

Runs at the commit stage, only at the all level.

A long function does more than one job, and a reader has to hold all of it at once.

Split the function by responsibility, or raise limits.python.max_function_lines with a reason.

A Python function over limits.python.max_function_lines reports function-lines with its count. Split it into functions that each do one job.

gspot ignore python/function-size --paths "<path>" --reason "<why>"

Checks that pyproject.toml lists every dependency, with no hand-kept requirements file and no pip install.

Runs at the commit stage, only at the all level, once per scope.

Two dependency lists drift apart, and the image installs packages the lockfile never pinned.

Export the requirements file from the lockfile, declare it generated, and replace pip install with the locked command.

A requirements.txt kept by hand beside a locked project reports a second dependency list. Export it from the lockfile, declare it generated, and install from the lock.

Rule What it checks What to do
requirements-file The scope keeps no requirements file by hand beside its lockfile. Generate the file from the lockfile and mark it generated in .gitattributes, or delete it.
pip-install No shell script, YAML or TOML file, or Dockerfile installs a package with pip install. Add the package to pyproject.toml and install it from the lockfile.
gspot ignore python/pip-installs --paths "<path>" --reason "<why>"
gspot ignore python/pip-installs --rule requirements-file --reason "<why>"

Finds docstrings that hold a placeholder word, repeat the name of their function or class, or start a class docstring with Class that, Class for, or A class.

Runs at the commit stage, only at the all level.

A docstring that says nothing satisfies the lint rule and wastes the line.

Say what the function or class does that its name does not, or for whom it exists.

A docstring that only repeats a function or class name reports a placeholder. Describe the behavior, the arguments, and the effects that the name leaves out.

gspot ignore python/placeholder-docstrings --paths "<path>" --reason "<why>"
Setting What it sets
python.externals Modules that the host application provides at run time, such as folder_paths. A name covers its submodules.
python.docstring_convention The docstring style that Ruff and pydoclint check.
python.import_folders Folders that Python imports resolve from, for basedpyright and the import rules check.
tools.ruff.rules Ruff rules or rule prefixes to run on top of the rules of the level, such as ANN. Ignore a finding with gspot ignore python/ruff --rule <rule> --reason "<why>".
Rule file Installed when
.gspot/rules/PYTHON.md Always
.gspot/rules/TYPING.md Always
Tool Version
uv 0.13.1
ruff 0.17.1
basedpyright 1.40.2
pydoclint 0.11.1
deptry 0.25.1
vulture 2.16

ruff.toml, pyrightconfig.json, .gspot/configurations/python/ruff.toml, and .gspot/configurations/python/basedpyright.json

**/.venv/**, **/venv/**, **/__pycache__/**, **/.pytest_cache/**, **/.ruff_cache/**, and **/.mypy_cache/**. repository/local-files reports a tracked file at these paths.