Skip to content

RUF067: Allow dunder-named assignments in non-strict mode#24089

Merged
MichaReiser merged 2 commits intoastral-sh:mainfrom
bitloi:fix/ruf067-dunder-assignments-22822
Mar 30, 2026
Merged

RUF067: Allow dunder-named assignments in non-strict mode#24089
MichaReiser merged 2 commits intoastral-sh:mainfrom
bitloi:fix/ruf067-dunder-assignments-22822

Conversation

@bitloi
Copy link
Copy Markdown
Contributor

@bitloi bitloi commented Mar 20, 2026

Summary

#22822: tools like mkinit use dunder names (__submodules__, etc.) in __init__.py. RUF067 only allowed a fixed list, so those were flagged.

When strictly-empty-init-modules is off, the rule now ignores assignments (including += and annotated assigns) if every target is a simple name and each name is a dunder (is_dunder in ruff_python_ast). Chained assigns still need every target to be a dunder. Strict mode is unchanged.

Also means non-extend_path __path__ = … is allowed in non-strict mode, per the issue discussion.

Closes #22822

Test Plan

Updated RUF067/modules/__init__.py and the two RUF067 snapshots. Ran cargo test -p ruff_linter --lib and clippy on ruff_linter.

@astral-sh-bot astral-sh-bot bot requested a review from amyreese March 20, 2026 19:16
@bitloi bitloi changed the title [ruff] RUF067: allow dunder assignments when not strict [ruff] Allow dunder-named assignments when not strict (RUF067)` per convention Mar 20, 2026
@bitloi bitloi force-pushed the fix/ruf067-dunder-assignments-22822 branch from 21e691d to eb67799 Compare March 20, 2026 19:58
@bitloi
Copy link
Copy Markdown
Contributor Author

bitloi commented Mar 25, 2026

Hi @MichaReiser Can you review my pr and share your feedback?

@MichaReiser
Copy link
Copy Markdown
Member

I know you don'd mean any harm. But please give us some more time. We give our best to review PRs and respond to issues in a timely manner and more notifications doesn't help.

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels Mar 30, 2026
@MichaReiser MichaReiser force-pushed the fix/ruf067-dunder-assignments-22822 branch from eb67799 to 379f50b Compare March 30, 2026 09:17
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 30, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -10 violations, +0 -0 fixes in 5 projects; 51 projects unchanged)

DisnakeDev/disnake (+0 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- disnake/__init__.py:13:1: RUF067 `__init__` module should only contain docstrings and re-exports
- disnake/__init__.py:15:1: RUF067 `__init__` module should only contain docstrings and re-exports
- disnake/__init__.py:16:1: RUF067 `__init__` module should only contain docstrings and re-exports

milvus-io/pymilvus (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- pymilvus/__init__.py:17:1: RUF067 `__init__` module should only contain docstrings and re-exports

pandas-dev/pandas (+0 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- pandas/__init__.py:184:1: RUF067 `__init__` module should only contain docstrings and re-exports
- pandas/__init__.py:3:1: RUF067 `__init__` module should only contain docstrings and re-exports

scikit-build/scikit-build (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- skbuild/__init__.py:13:1: RUF067 `__init__` module should only contain docstrings and re-exports

astropy/astropy (+0 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- astropy/__init__.py:195:1: RUF067 `__init__` module should only contain docstrings and re-exports
- astropy/coordinates/builtin_frames/__init__.py:243:1: RUF067 `__init__` module should only contain docstrings and re-exports
- astropy/io/votable/validator/__init__.py:5:1: RUF067 `__init__` module should only contain docstrings and re-exports

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF067 10 0 10 0 0

@MichaReiser MichaReiser changed the title [ruff] Allow dunder-named assignments when not strict (RUF067)` per convention RUF067: Allow dunder-named assignments in non-strict mode Mar 30, 2026
@MichaReiser MichaReiser merged commit 6062fb7 into astral-sh:main Mar 30, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom dunder variables and RUF067

3 participants