Skip to main content

CLI tool for checking stale docstrings.

Project description

pystaleds

Code Tests Coverage Status Linting

Tool to check for docstring stale status compared to function signature.

Compares thing such as order of arguments, type mismatches, absence of arguments etc.

Installing

You can install the package directly via pip using

pip install pystaleds

You can also simply build the binary using this repository directly with Rust. For instance,

cargo build -r
./target/release/pystaleds test_folder

would run the program to check the files inside test_folder in this repository.

Example

Suppose we have a function f as below.

def f(x):
    """This is my function.

    Args:
        x: This is my variable

    Returns:
        I just return whatever was passed to me.
    """
    return x

In a new change, we want to add a flag in order to reverse the argument or not.

def f(x, reverse):
    """This is my function.

    Args:
        x: This is my variable

    Returns:
        I just return whatever was passed to me.
    """
    if reverse:
        return -x
    else:
        return x

Note that we didn't change the docstring to reflect that we have a new variable. This is precisely the type of thing we want to identify.

Running v0.1.1 of pystaleds, we would get the following results for each one of those files:

 Success!
ERROR pystaleds::rules_checking: test.py: Line 1: Args from function: [("x", None), ("reverse", None)]. Args from docstring: [("x", None)]
Error: found errors in 1 file

The None that is present in that log line pertains to the types of the arguments in case they are type hinted.

Indeed, if our code were:

def f(x: int, reverse: bool):
    """This is my function.

    Args:
        x (int): This is my variable

    Returns:
        int: I just return whatever was passed to me.
    """
    if reverse:
        return -x
    else:
        return x

we would get:

ERROR pystaleds::rules_checking: test.py: Line 1: Args from function: [("x", Some("int")), ("reverse", Some("bool"))]. Args from docstring: [("x", Some("int"))]
Error: found errors in 1 file

If we change our code to

def f(x: int, reverse: bool):
    """This is my function.

    Args:
        x (int): This is my variable
        reverse: Whether to reverse before returning.

    Returns:
        int: I just return whatever was passed to me.
    """
    if reverse:
        return -x
    else:
        return x

we fix the issue! ✅ Success!

Note, however, that if you put mismatching types for the signature and the docstring, it will again raise errors.

Options

The only required argument is the path, which can be either a folder or an isolated file. In case it is a folder, it will run through its contents recursively.

Optional boolean arguments include:

  • --allow-hidden (--ah): This will include hidden files (i.e., those starting with ".") in the directory traversal.
  • --break-on-empty-line (--be): This will consider an empty line as a signal that the arguments section of the docstring has ended.
  • --forbid-no-docstring (--nd): This will raise an error in case a docstring is absent in a function definition.
  • --forbid-no-args-in-docstring (--na): This will raise an error in case a docstring does not have an arguments section.
  • --forbid_untyped_docstrings (--nu): This will raise an error in case a docstring has untyped arguments.

Optional non-boolean arguments include:

  • --glob (-g): Allows passing a glob that will determine which files to consider. In order for this to work, the path given to the program must be a folder. Then, the glob will be considered having such folder as root.
  • --docstyle (-s): Allows selecting the specific docstyle as a source for parsing. Defaults to auto-detect, which will try both google and numpy and use the one that works. But can be chosen to be specifically google or numpy.

Benchmarking

The benchmark below (done with hyperfine) includes the average times to run each checker tool on my machine across different projects. The test_folder refers to the folder on the root of this repo with two simple .py files.

If the time would be over 1 minute, it is indicated as NaN in the table, as I just stopped the test.

Checker pandas [ms] numpy [ms] fastapi [ms] test_folder [ms]
pystaleds 21.7 17.9 19.2 2.6
pystaleds (with tree-sitter parsing) 616.0 370.4 102.5 4.1
pydoclint 7418 3513 714.6 62.5
darglint NaN NaN 1152 125.3
docsig NaN NaN 19353 527.0

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

pystaleds-0.1.7.tar.gz (25.3 kB view hashes)

Uploaded Source

Built Distributions

pystaleds-0.1.7-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pystaleds-0.1.7-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

pystaleds-0.1.7-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

pystaleds-0.1.7-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

pystaleds-0.1.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pystaleds-0.1.7-pp310-pypy310_pp73-manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686

pystaleds-0.1.7-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pystaleds-0.1.7-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

pystaleds-0.1.7-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

pystaleds-0.1.7-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

pystaleds-0.1.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pystaleds-0.1.7-pp39-pypy39_pp73-manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686

pystaleds-0.1.7-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pystaleds-0.1.7-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

pystaleds-0.1.7-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

pystaleds-0.1.7-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

pystaleds-0.1.7-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pystaleds-0.1.7-pp38-pypy38_pp73-manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686

pystaleds-0.1.7-cp312-none-win_amd64.whl (632.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

pystaleds-0.1.7-cp312-none-win32.whl (599.3 kB view hashes)

Uploaded CPython 3.12 Windows x86

pystaleds-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pystaleds-0.1.7-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

pystaleds-0.1.7-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

pystaleds-0.1.7-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

pystaleds-0.1.7-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

pystaleds-0.1.7-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.12+ i686

pystaleds-0.1.7-cp312-cp312-macosx_11_0_arm64.whl (805.1 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pystaleds-0.1.7-cp312-cp312-macosx_10_12_x86_64.whl (824.5 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

pystaleds-0.1.7-cp311-none-win_amd64.whl (632.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pystaleds-0.1.7-cp311-none-win32.whl (599.3 kB view hashes)

Uploaded CPython 3.11 Windows x86

pystaleds-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pystaleds-0.1.7-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

pystaleds-0.1.7-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

pystaleds-0.1.7-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

pystaleds-0.1.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pystaleds-0.1.7-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.12+ i686

pystaleds-0.1.7-cp311-cp311-macosx_11_0_arm64.whl (805.1 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pystaleds-0.1.7-cp311-cp311-macosx_10_12_x86_64.whl (824.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

pystaleds-0.1.7-cp310-none-win_amd64.whl (632.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pystaleds-0.1.7-cp310-none-win32.whl (599.3 kB view hashes)

Uploaded CPython 3.10 Windows x86

pystaleds-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pystaleds-0.1.7-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

pystaleds-0.1.7-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

pystaleds-0.1.7-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

pystaleds-0.1.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pystaleds-0.1.7-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686

pystaleds-0.1.7-cp310-cp310-macosx_11_0_arm64.whl (805.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pystaleds-0.1.7-cp310-cp310-macosx_10_12_x86_64.whl (824.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

pystaleds-0.1.7-cp39-none-win_amd64.whl (632.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pystaleds-0.1.7-cp39-none-win32.whl (599.3 kB view hashes)

Uploaded CPython 3.9 Windows x86

pystaleds-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pystaleds-0.1.7-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

pystaleds-0.1.7-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

pystaleds-0.1.7-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

pystaleds-0.1.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pystaleds-0.1.7-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

pystaleds-0.1.7-cp38-none-win_amd64.whl (632.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pystaleds-0.1.7-cp38-none-win32.whl (599.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

pystaleds-0.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pystaleds-0.1.7-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

pystaleds-0.1.7-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

pystaleds-0.1.7-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

pystaleds-0.1.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pystaleds-0.1.7-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

Supported by

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