ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Missing D10* for "public" class / function / module in "private" module

Open szleb opened this issue 1 year ago • 1 comments
trafficstars

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.

szleb avatar Jan 17 '24 09:01 szleb

This is an interesting case because it shows that there's a cycle:

  • __init__.py depends on _private.py to know the type of PublicClass
  • PublicClass (_private.py) depends on __init__.py to know that PublicClass is public.

This is related to https://github.com/astral-sh/ruff/issues/7154

MichaReiser avatar Mar 21 '24 13:03 MichaReiser