Skip to main content

doc901

doc901 is a simple tool designed to ensure that Python methods and functions with a high cyclomatic complexity have proper docstrings. It uses ruff to analyze complexity and missing docstring on the same line.

Why?

Maintaining clean and readable code is crucial. Methods or functions with high complexity can be challenging to understand, especially without documentation.

While ruff provides rules for checking complexity (C901) and missing docstrings on methods and functions (D102 and D103, respectively), there is no built-in way to link them together. Enabling D10x project-wide flagging all methods and functions without a docstring (even if they are simple and self-explanatory) could be overwhelming in large projects.

doc901 bridges this gap by flagging errors only when the complexity is enough to demand a docstring, so you can improve your code incrementally,

Of course, the name comes after the C901 rule code ;-)

Use and install

The easiest way is via uvx.

uvx doc901 path/to/file.py

To analyze an entire directory:

uvx doc901 path/to/directory/

The default allowed complexity is 4, meaning any function or method with McCabe 5 or more will require a docstring.

uvx doc901 --max-complexity=3 path/to/file.py 

See --help for more options.

To install the tool permanently:

uv tool install doc901

Example

Imagine you have a file example.py with the following methods:

def complex_function_without_docstring():
    for i in range(10):
        if i % 2 == 0:
            for j in range(5):
                print(i, j)

Running doc901 on this file:

python doc901.py example.py

Output:

example.py:1: `complex_function_without_docstring` is too complex (5 > 4). Add a docstring.

Ignoring legacy errors

There are several ways to ignore errors:

  • Since ruff is used under the hood, you can add noqa: D102 or noqa: D103 comments to the line that defines the method or function.

Alternatively, if you have a large codebase with many existing errors, you can use the --ignore flag and pass a JSON file containing the errors to ignore.

You can generate this file by running the tool with the --json flag:

uvx doc901 --json ... > ignored.jwill output a JSON file son

This will output a JSON file listing the errors found. You can then edit this file to remove any errors you don't want to ignore. For example, the output might look like this:

[
    {
        "path": "example.py", 
        "row": 8, 
        "name": "complex_method_without_docstring",
        "complexity": 5
    }
]

Then in your normal runs, pass this file to the --ignore flag:

uvx doc901 --ignore ignored.json ...

Any violation that matches both the path and the name will be ignored. Note that the row is intentionally omitted because the exact line where a function is defined might change frequently. You can also add additional metadata to the JSON file, such as the person responsible for fixing the issue.

Contribution

Feel free to open issues or submit pull requests if you encounter bugs or have suggestions for improvement. This tool is lightweight but can be extended to cover more advanced checks.

License

This project is open-source and available under the MIT License. See the LICENSE file for details.

Metadata

Release files for doc901 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for doc901 0.2.1
File Size Uploaded Provenance
doc901-0.2.1.tar.gz 3.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for doc901 0.2.1
File Interpreter ABI Platform
doc901-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 kB

Release files / doc901-0.2.1.tar.gz

Download URL doc901-0.2.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0fe95e0dd70c249f3d606b52bd7c13f8ea129a9318eaee241a3a4fc80cf9b422
BLAKE2b-256 checksum
How to use checksums
ed8241958fcc4a28ccaffd620d68f40e51cd6325ac49f60e35177c9e9ac15665
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 29, 2025.

Transparency log

Release files / doc901-0.2.1-py3-none-any.whl

Download URL doc901-0.2.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbf65ae26f423a4f168259ee310e86fd7299daf510afaa2049a0704774030b6b
BLAKE2b-256 checksum
How to use checksums
6fd0b488a9b5b1b2f1b7912d031b89230d94b78317d09b8213e00df8f3089bfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 29, 2025.

Transparency log

Security for doc901 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for doc901-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 29, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page