astral-sh / astral-sh/ruff

D1XX rules don't work when functions are imported into a public file

Open
#7,154 3 comments 5 reactions 0 assignees View on GitHub
type-inference
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

The D1XX rules check if docstrings for public functions/classes exist. However, I think they are missing a common pattern of defining "public objects". Namely, defining them in "private" (aka leading underscore) files and then importing them into a top-level `__init__`.

```python
# mypackage/__init__.py
from mypackage._methods implement my_function

__all__ = ["my_function"]
```

```python
# mypackage/_methods.py

def my_function():
pass
```

In this case, I would expect ruff to identify `my_function` as a public function, as it is imported in a public module (and even added to `__all__`).

Contributor guide

Open the contributing guide

Research direction

Start by locating the D1XX rule implementation and its existing tests, then reproduce the package layout shown with a private module imported by a top-level __init__.py. Done means public functions and classes exposed through that public module, especially those listed in __all__, are checked for docstrings.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.