python
Python sources: lint, layout, strict types, docstrings that match their signatures, and no unused code or dependencies. Guide: Python.
Selected when
Section titled “Selected when”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.
Checks
Section titled “Checks”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.
What to do
Section titled “What to do”Run the fix: command that the report prints for the rules that fix themselves.
Example
Section titled “Example”eval(user_input) reports S307. Parse the input instead, and allow only known operations.
Turn it off
Section titled “Turn it off”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 importruff-format
Section titled “ruff-format”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.
What to do
Section titled “What to do”Run the fix: command that the report prints.
Example
Section titled “Example”value=1 differs from the Ruff output. Run gspot check --fix to get value = 1.
Turn it off
Section titled “Turn it off”gspot ignore python/ruff-format --paths "<path>" --reason "<why>"basedpyright
Section titled “basedpyright”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.
What to do
Section titled “What to do”Fix the type, or narrow it where the value arrives.
Example
Section titled “Example”count: int = "one" reports an incompatible type. Assign a number, such as count: int = 1, or change the annotation to str.
Turn it off
Section titled “Turn it off”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 abovepydoclint
Section titled “pydoclint”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.
What to do
Section titled “What to do”Bring the docstring in line with the signature.
Example
Section titled “Example”A docstring that documents name for a function that takes path reports a mismatch. Document path instead.
Turn it off
Section titled “Turn it off”gspot ignore python/pydoclint --paths "<path>" --reason "<why>"gspot ignore python/pydoclint --rule <rule> --reason "<why>"deptry
Section titled “deptry”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.
What to do
Section titled “What to do”Declare the dependency, or remove the one nothing imports.
Example
Section titled “Example”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.
Turn it off
Section titled “Turn it off”gspot ignore python/deptry --paths "<path>" --reason "<why>"gspot ignore python/deptry --rule <rule> --reason "<why>"vulture
Section titled “vulture”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.
What to do
Section titled “What to do”Delete the unused definition or the unreachable code.
Example
Section titled “Example”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.
Lint rules
Section titled “Lint rules”| 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. |
Turn it off
Section titled “Turn it off”gspot ignore python/vulture --paths "<path>" --reason "<why>"gspot ignore python/vulture --rule unreachable-code --reason "<why>"function-size
Section titled “function-size”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.
What to do
Section titled “What to do”Split the function by responsibility, or raise limits.python.max_function_lines with a reason.
Example
Section titled “Example”A Python function over limits.python.max_function_lines reports function-lines with its count. Split it into functions that each do one job.
Turn it off
Section titled “Turn it off”gspot ignore python/function-size --paths "<path>" --reason "<why>"pip-installs
Section titled “pip-installs”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.
What to do
Section titled “What to do”Export the requirements file from the lockfile, declare it generated, and replace pip install with the locked command.
Example
Section titled “Example”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.
Lint rules
Section titled “Lint rules”| 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. |
Turn it off
Section titled “Turn it off”gspot ignore python/pip-installs --paths "<path>" --reason "<why>"gspot ignore python/pip-installs --rule requirements-file --reason "<why>"placeholder-docstrings
Section titled “placeholder-docstrings”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.
What to do
Section titled “What to do”Say what the function or class does that its name does not, or for whom it exists.
Example
Section titled “Example”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.
Turn it off
Section titled “Turn it off”gspot ignore python/placeholder-docstrings --paths "<path>" --reason "<why>"Settings
Section titled “Settings”| 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>". |
Rules for coding agents
Section titled “Rules for coding agents”| Rule file | Installed when |
|---|---|
.gspot/rules/PYTHON.md |
Always |
.gspot/rules/TYPING.md |
Always |
Tools and versions
Section titled “Tools and versions”| 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 |
Files gspot writes
Section titled “Files gspot writes”ruff.toml, pyrightconfig.json, .gspot/configurations/python/ruff.toml, and .gspot/configurations/python/basedpyright.json
Paths that must stay out of Git
Section titled “Paths that must stay out of Git”**/.venv/**, **/venv/**, **/__pycache__/**, **/.pytest_cache/**, **/.ruff_cache/**, and **/.mypy_cache/**. repository/local-files reports a tracked file at these paths.