PyCQA / pydocstyle

docstring style checker
http://pydocstyle.org
MIT License
1.11k stars 189 forks source link

Module privacy ignored #592

Open Georacer opened 2 years ago

Georacer commented 2 years ago

Hello everyone!

Thanks a bunch for maintaining our quality standards and sorry in advance if this is the wrong place to ask this question:

I'm applying the flake8 hook using the pre-commit github hook. Part of my error report is this:

...
[...]/_helpers.py:21:1: D102 Missing docstring in public method
[...]/_helpers.py:27:1: D102 Missing docstring in public method
[...]/_helpers.py:36:1: D103 Missing docstring in public function
[...]/_helpers.py:61:1: D103 Missing docstring in public function
[...]/_helpers.py:74:1: D101 Missing docstring in public class
...

Unless I misunderstood the documentation, _helpers.py should act as a private parent, preventing all classes and functions inside of it raising D10X errors. Am I understanding this wrong or is this an bug?

poetry show reports the following versions:

flake8                            4.0.1      the modular source code checker: pep8 pyflakes and co
flake8-bandit                     2.1.2      Automated security testing with bandit and flake8.
flake8-bugbear                    21.9.2     A plugin for flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pyco...
flake8-docstrings                 1.6.0      Extension for flake8 which uses pydocstyle to check docstrings
flake8-polyfill                   1.0.2      Polyfill package for Flake8 plugins
flake8-rst-docstrings             0.2.3      Python docstring reStructuredText (RST) validator

Thanks in advance, George

danieleades commented 2 years ago

In seeing a similar issue for modules which are not prefixed with an underscore, but which are excluded from an __all__ statement (so should not be considered public). I don't see the issue when using flake8-docstrings with vscode, but I do see it when using pre-commit. I'm guessing this has something to do with the way files are passed

sigmavirus24 commented 2 years ago

pre-commit (and other tools) will explicitly pass the filename if I remember correctly. When passed explicitly versus discovered in a path, that changes how most told think about linting. Maybe use a pre-commit exclude regex for this problem

edmorley commented 1 year ago

I'm seeing this issue when using pydocstyle locally, and calling it via pydocstyle my_package_dir, where it's (incorrectly) reporting issues in eg:

my_package_dir/_internal/logging.py:6 in public function `configure_logging`:
        D103: Missing docstring in public function

Since _internal is not public, this shouldn't be reported, given the pydocstyle docs say that all parents need to be public, not just the immediate module:

In order for a construct to be considered public, its immediate parent must also be public. Since this definition is recursive, it means that all of its parents need to be public.

(From https://www.pydocstyle.org/en/stable/error_codes.html#how-publicity-is-determined)