Skip to content

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

Merged
MichaReiser merged 2 commits into
astral-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 into
astral-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
nicopauss pushed a commit to Intersec/lib-common that referenced this pull request Jun 4, 2026
##### [\`v0.15.10\`](https://github.com/astral-sh/ruff/blob/HEAD/CHANGELOG.md#01510)

Released on 2026-04-09.

##### Preview features

- \[`flake8-logging`] Allow closures in except handlers (`LOG004`) ([#24464](astral-sh/ruff#24464))
- \[`flake8-self`] Make `SLF` diagnostics robust to non-self-named variables ([#24281](astral-sh/ruff#24281))
- \[`flake8-simplify`] Make the fix for `collapsible-if` safe in `preview` (`SIM102`) ([#24371](astral-sh/ruff#24371))

##### Bug fixes

- Avoid emitting multi-line f-string elements before Python 3.12 ([#24377](astral-sh/ruff#24377))
- Avoid syntax error from `E502` fixes in f-strings and t-strings ([#24410](astral-sh/ruff#24410))
- Strip form feeds from indent passed to `dedent_to` ([#24381](astral-sh/ruff#24381))
- \[`pyupgrade`] Fix panic caused by handling of octals (`UP012`) ([#24390](astral-sh/ruff#24390))
- Reject multi-line f-string elements before Python 3.12 ([#24355](astral-sh/ruff#24355))

##### Rule changes

- \[`ruff`] Treat f-string interpolation as potential side effect (`RUF019`) ([#24426](astral-sh/ruff#24426))

##### Server

- Add support for custom file extensions ([#24463](astral-sh/ruff#24463))

##### Documentation

- Document adding fixes in CONTRIBUTING.md ([#24393](astral-sh/ruff#24393))
- Fix JSON typo in settings example ([#24517](astral-sh/ruff#24517))

##### Contributors

- [@charliermarsh](https://github.com/charliermarsh)
- [@dylwil3](https://github.com/dylwil3)
- [@silverstein](https://github.com/silverstein)
- [@anishgirianish](https://github.com/anishgirianish)
- [@shizukushq](https://github.com/shizukushq)
- [@zanieb](https://github.com/zanieb)
- [@AlexWaygood](https://github.com/AlexWaygood)
##### [\`v0.15.9\`](https://github.com/astral-sh/ruff/blob/HEAD/CHANGELOG.md#0159)

Released on 2026-04-02.

##### Preview features

- \[`pyflakes`] Flag annotated variable redeclarations as `F811` in preview mode ([#24244](astral-sh/ruff#24244))
- \[`ruff`] Allow dunder-named assignments in non-strict mode for `RUF067` ([#24089](astral-sh/ruff#24089))

##### Bug fixes

- \[`flake8-errmsg`] Avoid shadowing existing `msg` in fix for `EM101` ([#24363](astral-sh/ruff#24363))
- \[`flake8-simplify`] Ignore pre-initialization references in `SIM113` ([#24235](astral-sh/ruff#24235))
- \[`pycodestyle`] Fix `W391` fixes for consecutive empty notebook cells ([#24236](astral-sh/ruff#24236))
- \[`pyupgrade`] Fix `UP008` nested class matching ([#24273](astral-sh/ruff#24273))
- \[`pyupgrade`] Ignore strings with string-only escapes (`UP012`) ([#16058](astral-sh/ruff#16058))
- \[`ruff`] `RUF072`: skip formfeeds on dedent ([#24308](astral-sh/ruff#24308))
- \[`ruff`] Avoid re-using symbol in `RUF024` fix ([#24316](astral-sh/ruff#24316))
- \[`ruff`] Parenthesize expression in `RUF050` fix ([#24234](astral-sh/ruff#24234))
- Disallow starred expressions as values of starred expressions ([#24280](astral-sh/ruff#24280))

##### Rule changes

- \[`flake8-simplify`] Suppress `SIM105` for `except*` before Python 3.12 ([#23869](astral-sh/ruff#23869))
- \[`pyflakes`] Extend `F507` to flag `%`-format strings with zero placeholders ([#24215](astral-sh/ruff#24215))
- \[`pyupgrade`] `UP018` should detect more unnecessarily wrapped literals (UP018) ([#24093](astral-sh/ruff#24093))
- \[`pyupgrade`] Fix `UP008` callable scope handling to support lambdas ([#24274](astral-sh/ruff#24274))
- \[`ruff`] `RUF010`: Mark fix as unsafe when it deletes a comment ([#24270](astral-sh/ruff#24270))

##### Formatter

- Add `nested-string-quote-style` formatting option ([#24312](astral-sh/ruff#24312))

##### Documentation

- \[`flake8-bugbear`] Clarify RUF071 fix safety for non-path string comparisons ([#24149](astral-sh/ruff#24149))
- \[`flake8-type-checking`] Clarify import cycle wording for `TC001`/`TC002`/`TC003` ([#24322](astral-sh/ruff#24322))

##### Other changes

- Avoid rendering fix lines with trailing whitespace after `|` ([#24343](astral-sh/ruff#24343))

##### Contributors

- [@charliermarsh](https://github.com/charliermarsh)
- [@MichaReiser](https://github.com/MichaReiser)
- [@tranhoangtu-it](https://github.com/tranhoangtu-it)
- [@dylwil3](https://github.com/dylwil3)
- [@zsol](https://github.com/zsol)
- [@renovate](https://github.com/renovate)
- [@bitloi](https://github.com/bitloi)
- [@danparizher](https://github.com/danparizher)
- [@chinar-amrutkar](https://github.com/chinar-amrutkar)
- [@second-ed](https://github.com/second-ed)
- [@getehen](https://github.com/getehen)
- [@Redovo1](https://github.com/Redovo1)
- [@matthewlloyd](https://github.com/matthewlloyd)
- [@zanieb](https://github.com/zanieb)
- [@InSyncWithFoo](https://github.com/InSyncWithFoo)
- [@RenzoMXD](https://github.com/RenzoMXD)

Renovate-Branch: renovate/2024.6-ruff-0.15.x
Change-Id: Id4bd542d4f128b509284d9dcda312f2b39c29964
Priv-Id: 28ebcacdeffa50cec7a52eee59091a75ca5e9539
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