Skip to main content

Check signature params for proper documentation

Project description


docsig logo

License PyPI CI CodeQL pre-commit.ci status codecov.io readthedocs.org python3.10 Black isort pylint Security Status Known Vulnerabilities docsig

Check Python signature params for proper documentation

docsig is a Python documentation linter that ensures function and method signature parameters are properly documented in docstrings. It supports multiple docstring formats including reStructuredText (Sphinx), NumPy, and Google styles.

Maintain accurate and up-to-date Python documentation by automatically checking that all parameters in function signatures match their docstring documentation. Use docsig as a standalone tool, integrate it with flake8, or add it as a pre-commit hook to catch documentation issues before they reach your repository.

Contributing

If you are interested in contributing to docsig, please read about contributing here

Installation

$ pip install docsig

Usage

Commandline

usage: docsig [-h] [-V] [-l] [-n] [-v] [--check-class | --check-class-constructor]
              [--check-dunders] [--check-nested] [--check-overridden]
              [--check-property-returns] [--check-protected]
              [--check-protected-class-methods] [--ignore-args] [--ignore-kwargs]
              [--ignore-no-params] [--ignore-typechecker] [-d LIST] [-t LIST] [-e PATTERN]
              [-E PATH [PATH ...]] [-I] [-s STR]
              [path [path ...]]

Check signature params for proper documentation

positional arguments:
  path                  directories or files to check

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -l, --list-checks     display a list of all checks and their messages
  -n, --no-ansi         disable ansi output
  -v, --verbose         increase output verbosity
  --check-class         check class docstrings
  --check-class-constructor
                        check __init__ methods
  --check-dunders       check dunder methods
  --check-nested        check nested functions and classes
  --check-overridden    check overridden methods
  --check-property-returns
                        check property return values
  --check-protected     check protected functions and classes
  --check-protected-class-methods
                        check public methods belonging to protected classes
  --ignore-args         ignore args prefixed with an asterisk
  --ignore-kwargs       ignore kwargs prefixed with two asterisks
  --ignore-no-params    ignore docstrings where parameters are not documented
  --ignore-typechecker  ignore checking return values
  -d LIST, --disable LIST
                        comma separated list of rules to disable
  -t LIST, --target LIST
                        comma separated list of rules to target
  -e PATTERN, --exclude PATTERN
                        regular expression of files or dirs to exclude from checks
  -E PATH [PATH ...], --excludes PATH [PATH ...]
                        path glob patterns to exclude from checks
  -I, --include-ignored
                        check files even if they match a gitignore pattern
  -s STR, --string STR  string to parse instead of files

Options can also be configured with the pyproject.toml file

[tool.docsig]
check-dunders = false
check-overridden = false
check-protected = false
disable = [
    "SIG101",
    "SIG102",
    "SIG402",
]
target = [
    "SIG202",
    "SIG203",
    "SIG201",
]

Flake8

docsig can also be used as a flake8 plugin. Install flake8 and ensure your installation has registered docsig

$ flake8 --version
7.3.0 (docsig: 0.78.0, mccabe: 0.7.0, pycodestyle: 2.14.0, pyflakes: 3.4.0) CPython 3.10.19 on Darwin

And now use flake8 to lint your files

$ flake8 example.py
example.py:1:1: SIG202 includes parameters that do not exist (params-do-not-exist) 'function'

With flake8 the pyproject.toml config will still be the base config, though the ini files flake8 gets it config from will override the pyproject.toml config. For flake8 all args and config options are prefixed with sig to avoid any potential conflicts with other plugins

[flake8]
sig-check-dunders = True
sig-check-overridden = True
sig-check-protected = True

API

>>> from docsig import docsig
>>> string = '''
... def function(a, b, c) -> None:
...     """Docstring summary.
...
...     :param a: Description of a.
...     :param b: Description of b.
...     :param c: Description of c.
...     """
... '''
>>> docsig(string=string, no_ansi=True)
0
>>> string = '''
... def function(a, b) -> None:
...     """Docstring summary.
...
...     :param a: Description of a.
...     :param b: Description of b.
...     :param c: Description of c.
...     """
... '''
>>> docsig(string=string, no_ansi=True)
2 in function
    SIG202: includes parameters that do not exist (params-do-not-exist)
1

A full list of checks can be found here

Message Control

Documentation on message control

Classes

Documenting classes

pre-commit

docsig can be used as a pre-commit hook

It can be added to your .pre-commit-config.yaml as follows:

Standalone

repos:
  - repo: https://github.com/jshwi/docsig
    rev: v0.78.0
    hooks:
      - id: docsig
        args:
          - "--check-class"
          - "--check-dunders"
          - "--check-overridden"
          - "--check-protected"

or integrated with flake8

repos:
  - repo: https://github.com/PyCQA/flake8
    rev: "7.1.0"
    hooks:
      - id: flake8
        additional_dependencies:
          - docsig==0.78.0
        args:
          - "--sig-check-class"
          - "--sig-check-dunders"
          - "--sig-check-overridden"
          - "--sig-check-protected"

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

docsig-0.78.0.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

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

docsig-0.78.0-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file docsig-0.78.0.tar.gz.

File metadata

  • Download URL: docsig-0.78.0.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.19 Darwin/25.2.0

File hashes

Hashes for docsig-0.78.0.tar.gz
Algorithm Hash digest
SHA256 9329b221657f51492b52df5bb0ac45b2d0d63e1ce4f488a043cf0aadea07de16
MD5 b97cb9e71d54f0916d7afd739448fdd7
BLAKE2b-256 a63a81437c9a0c891e669289e057aaa6f4d4f5109f69767167ead115449ef0b1

See more details on using hashes here.

File details

Details for the file docsig-0.78.0-py3-none-any.whl.

File metadata

  • Download URL: docsig-0.78.0-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.19 Darwin/25.2.0

File hashes

Hashes for docsig-0.78.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9afd35d40f0fdafb07b75369e57aeb9c0ac778d556b650c3846c4b5fa614c7e2
MD5 ed7df5ae36a32d7665cb9a7e82f03e57
BLAKE2b-256 4712cc1fce8cfc48b8442ea585962132f10b722ed09c652ec26033dddb9adb53

See more details on using hashes here.

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