/docsig

Check signature params for proper documentation

Primary LanguagePythonMIT LicenseMIT

docsig

License PyPI CI pre-commit.ci status CodeQL codecov.io readthedocs.org python3.8 Black pylint Known Vulnerabilities

Check signature params for proper documentation

Supports reStructuredText (Sphinx), NumPy, and Google

Installation

$ pip install docsig

Usage

Commandline

usage: docsig [-h] [-v] [-c] [-D] [-o] [-p] [-P] [-i] [-a] [-k] [-n] [-S] [-s STR]
                         [-d LIST] [-t LIST]
                         [path [path ...]]

Check signature params for proper documentation

positional arguments:
  path                          directories or files to check (default: .)

optional arguments:
  -h, --help                    show this help message and exit
  -v, --version                 show program's version number and exit
  -c, --check-class             check class docstrings
  -D, --check-dunders           check dunder methods
  -o, --check-overridden        check overridden methods
  -p, --check-protected         check protected functions and classes
  -P, --check-property-returns  check property return values
  -i, --ignore-no-params        ignore docstrings where parameters are not documented
  -a, --ignore-args             ignore args prefixed with an asterisk
  -k, --ignore-kwargs           ignore kwargs prefixed with two asterisks
  -n, --no-ansi                 disable ansi output
  -S, --summary                 print a summarised report
  -s STR, --string STR          string to parse instead of files
  -d LIST, --disable LIST       comma separated list of rules to disable
  -t LIST, --target LIST        comma separated list of rules to target

Options can also be configured with the pyproject.toml file

If you find the output is too verbose then the report can be configured to display a summary

[tool.docsig]
check-dunders = false
check-overridden = false
check-protected = false
summary = true
disable = [
    "E101",
    "E102",
    "E103",
]
target = [
    "E102",
    "E103",
    "E104",
]

API

>>> from docsig import docsig
>>> string = """
... def function(param1, param2, param3) -> None:
...     '''Summary for passing docstring...
...
...     Explanation for passing docstring...
...
...     :param param1: About param1.
...     :param param2: About param2.
...     :param param3: About param3.
...     '''
...     """
>>> docsig(string=string)
0
>>> string = """
... def function(param1, param2) -> None:
...     '''Summary for failing docstring...
...
...     Explanation for failing docstring...
...
...     :param param1: About param1.
...     :param param2: About param2.
...     :param param3: About param3.
...     '''
... """
>>> docsig(string=string)
2
-
def function(✓param1, ✓param2, ✖None) ->None:
    """
    :param param1: ✓
    :param param2: ✓
    :param param3: ✖
    """
<BLANKLINE>
E102: includes parameters that do not exist
<BLANKLINE>
1

A full list of checks can be found here

Classes

Checking a class docstring is not enabled by default, as this check is opinionated, and won't suite everyone

This check will check documentation of __init__ under the class docstring, and not under __init__ itself

>>> string = """
... class Klass:
...     '''Summary for failing docstring...
...
...     Explanation for failing docstring...
...
...     :param param1: About param1.
...     :param param2: About param2.
...     :param param3: About param3.
...     '''
...     def __init__(self, param1, param2) -> None:
...         pass
... """
>>> docsig(string=string, check_class=True)
11 in Klass
-----------
class Klass:
    """
    :param param1: ✓
    :param param2: ✓
    :param param3: ✖
    """
<BLANKLINE>
    def __init__(✓param1, ✓param2, ✖None) ->None:
<BLANKLINE>
E102: includes parameters that do not exist
<BLANKLINE>
1

Checking class docstrings can be permanently enabled in the pyproject.toml file

[tool.docsig]
check-class = true

pre-commit

docsig can be used as a pre-commit hook

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

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