ruff
ruff copied to clipboard
Missing D10* for "public" class / function / module in "private" module
Hi there,
imagine you have the following folder with files package ├── __init__.py └── _private.py
Content of _private.py:
class PublicClass:
pass
Content of __init__.py:
from ._private import PublicClass
__all__ = ["PublicClass"]
If you now run
ruff package --select D
the output is
package\__init__.py:1:1: D104 Missing docstring in public package
I miss the error
package\_private.py:1:7: D101 Missing docstring in public class
Running pydocstyle does show D101 but unfortunately no matter whether __init__.py does export PublicClass or not.
In my opinion the optimal behavior would be to raise D101 when PublicClass is exported in __init__.py and to NOT raise the error when PublicClass is not exported in a public package (or module) but hidden by the "private" module _private.py. But I have no idea if this is feasible. If not, I would prefer the behavior of pydocstyle which seems just raise D10* for any function, module or class not starting with a single underline.
This is an interesting case because it shows that there's a cycle:
__init__.pydepends on_private.pyto know the type ofPublicClassPublicClass(_private.py) depends on__init__.pyto know thatPublicClassis public.
This is related to https://github.com/astral-sh/ruff/issues/7154