Skip to main content

Enforce docstrings on complex function and methods

Project description

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? How?

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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doc901-0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

doc901-0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file doc901-0.1.tar.gz.

File metadata

  • Download URL: doc901-0.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for doc901-0.1.tar.gz
Algorithm Hash digest
SHA256 12dfb8c9e9332142d2818a3f4ea45575d89dfd2a97b71e32b067935fb870c3e2
MD5 71fb21adf5e206e212c3aab382695ef3
BLAKE2b-256 2f29dbe69b12db4b31d444d57a08e417a15692f513f4521b51a2ce04aa9ceca7

See more details on using hashes here.

Provenance

The following attestation bundles were made for doc901-0.1.tar.gz:

Publisher: cd.yml on Shiphero/doc901

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file doc901-0.1-py3-none-any.whl.

File metadata

  • Download URL: doc901-0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for doc901-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef9e261fb79225361f75d08d73cbc937f0cb063f67b85a0b93f8a5393a4d393a
MD5 85e6ce64753083c0132e9c1f06000db7
BLAKE2b-256 910670f7e6ac65a2bfa4a22eec9714ed3087258f0e576c6359371c5361ceb295

See more details on using hashes here.

Provenance

The following attestation bundles were made for doc901-0.1-py3-none-any.whl:

Publisher: cd.yml on Shiphero/doc901

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page