Skip to main content

pydoctest: docstring signature verification

PyPI version pydoctest Tests PyPI - Downloads codecov

File issues here: Issues tracker

Motivation

Pydoctest helps you verify that your docstrings match your function signatures. As a codebase evolves, you can some times forget to update the docstrings.

Installation

Install pydoctest with pip:

$ python3 -m pip install pydoctest

Usage

Navigate to your project location, and execute pydoctest

$ pydoctest

With no pydoctest.json configuration file, it will by default validate all .py files recursively in the current directory (**/*.py). See the configuration section for options. If you get errors with modules not being found, try placing the pydoctest.json differently or executing inside the package.

Output

Pydoctest supports outputting results either as JSON or Text with different verbosity options. By default, Text is returned. To specify the output, invoke with --reporter argument:

$ pydoctest --reporter [json | text]

For Text-output, --verbosity can be provided with a value of 0 (quiet), 1 (show failed) or 2 (show all).

$ pydoctest --reporter text --verbosity 1

Configuration

Pydoctest can be configured with a config JSON file. By default, it will search for pydoctest.json in the directory pydoctest is executed. A path can also be provided when executing:

$ pydoctest --config /path/to/pydoctest.json

Example pydoctest.json:

{
    "include_paths": [ "server/*.py" ],
    "fail_on_missing_docstring": true,
    "parser": "google",
}

Docstring format can be specified with the --parser argument:

$ pydoctest --parser google

Currently, only google, numpy and sphinx are supported.

Full list of configuration options:

  • "include_paths": [ List of strings ] # Patterns to search modules with. Defaults to [**/*.py]
  • "exclude_paths": [ List of strings ] # Patterns to exclude modules with. Defaults to ["**/__init__.py", "**/setup.py"]
  • "verbosity": [ 0 | 1 | 2 ] # How much to print, 0 = quiet, 1 = show failed, 2 = show all.
  • "parser": [ "google" (default) | "sphinx" | "numpy" ] # Docstring format to use. Please raise an issue if you need other formats implemented.
  • "fail_on_missing_docstring": [ true | false (default) ] # Mark a function as failed, if it does not have a docstring.
  • "fail_on_missing_summary": [ true | false (default) ] # Mark a function as failed, if it does have a docstring, but no summary.
  • "fail_on_raises_section": [ true (default) | false ] # Mark a function as failed, if docstring doesn't mention raised exceptions correctly.
  • "exclude_classes": [ List of strings ] # Patterns to exclude classes with, e.g. ["Test*]"
  • "exclude_methods": [ List of strings ] # Patterns to exclude class methods with, e.g. for private methods you would use ["__*]"
  • "exclude_functions": [ List of strings ] # Patterns to exclude functions with, e.g. for private methods you would use ["__*]"

CLI

Printing the help message shows all currently implemented cli options.

pydoctest --help

Example

# example_file.py
def func_type_mismatch(self, a: int) -> int:
    """[summary]

    Args:
        a (float): [description]        <-- float is not int

    Returns:
        int: [description]
    """
    pass

# /example_file.py::func_type_mismatch FAIL | Argument type differ. Argument 'a' was expected (from signature) to have type '<class 'int'>', but has (in docs) type '<class 'float'>'
Tested 1 function(s) across 1 module(s).
Succeeded: 0, Failed: 1, Skipped: 0

Editor support

Currently pydoctest is supported by vscode: https://github.com/jepperaskdk/vscode-pydoctest

example_file_vscode

License

Pydoctest is licensed under the terms of the MIT License (see the LICENSE file).

Metadata

Release files for pydoctest 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 pydoctest 0.2.1
File Size Uploaded
pydoctest-0.2.1.tar.gz 27.7 kB Details

Built distribution (wheel)

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

Total release size: 68.9 kB

Release files / pydoctest-0.2.1.tar.gz

Download URL pydoctest-0.2.1.tar.gz
Size 27.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d68efde75ca17994d88801bd6081cff3459c9e8211d659dbd9068d50e21ed1f8
BLAKE2b-256 checksum
How to use checksums
bb85fbd6f09c9731cb374a4f6a2f07ae094a24dc034dcae32a3428e6fc992c5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

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

Download URL pydoctest-0.2.1-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8044448e3bc6471efb55443fc6a373e228f273635fb30f6f1ac97adde4be36cf
BLAKE2b-256 checksum
How to use checksums
5f2989443aaa85972ce971af63521fbac99b0ac2abfb4d7e66fdadf66af00b8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.22

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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