Skip to content

[flake8-import-conventions] Document that extend-aliases can override default aliases - #27191

Merged
ntBre merged 2 commits into
astral-sh:mainfrom
LHMQ878:docs/extend-aliases-override
Jul 28, 2026
Merged

[flake8-import-conventions] Document that extend-aliases can override default aliases#27191
ntBre merged 2 commits into
astral-sh:mainfrom
LHMQ878:docs/extend-aliases-override

Conversation

@LHMQ878

@LHMQ878 LHMQ878 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Closes #17097

Summary

The extend-aliases documentation only stated that entries "will be added to the aliases
mapping", which does not convey that an entry for a module that already has a default alias
replaces that default. As noted in the issue, this makes it possible to change or opt out
of a default alias without restating the whole aliases mapping.

This is a documentation-only change; the behaviour already works this way because the
settings resolver applies extend-aliases on top of aliases via HashMap::extend, so
matching keys are overwritten.

Test Plan

Verified the documented behaviour against ruff 0.12.4 using this sample file:

import numpy
import numpy as np
Config Result
default ICN001 numpyshould be imported asnp`` on line 1
numpy = "numpy" under extend-aliases ICN001 numpyshould be imported asnumpy`` on line 2, i.e. the aliased import is now the violation
numpy = "nmp" under extend-aliases both lines flagged, requiring nmp, so the default np is fully replaced

Also ran:

  • cargo fmt --check - passes.
  • cargo dev generate-all - regenerated ruff.schema.json so the new description is
    reflected there; confirmed the file is still valid JSON and contains the updated text.

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. As I noted on the issue, I'm not sure this is really an intended usage that we want to point users toward. I think I would make the minimal change necessary to acknowledge that this works, which would be something like:

 /// A mapping from module to conventional import alias. These aliases will
 /// be added to the [`aliases`](#lint_flake8-import-conventions_aliases) mapping
+/// and will override any existing `aliases` if the two settings overlap.

@ntBre ntBre added the documentation Improvements or additions to documentation label Jul 27, 2026
Per review, keep the change minimal and just acknowledge that entries
override an overlapping `aliases` entry, rather than presenting the
self-alias trick as a recommended way to opt out of a default.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@LHMQ878

LHMQ878 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Makes sense — reduced to exactly your suggested wording in 47b31fb.

Dropped the paragraph about using a self-alias to opt out of a default, and the numpy = "numpy" example line with it, so the docs no longer point anyone toward that usage. ruff.schema.json is regenerated from the doc comment, hence the second file.

The diff is now the one-liner you wrote, nothing else.

@ntBre
ntBre enabled auto-merge (squash) July 28, 2026 14:43
@ntBre ntBre changed the title [docs] Document that extend-aliases can override default aliases [flake8-import-conventions] Document that extend-aliases can override default aliases Jul 28, 2026
@ntBre
ntBre disabled auto-merge July 28, 2026 14:44
@ntBre
ntBre enabled auto-merge (squash) July 28, 2026 14:44
@ntBre
ntBre merged commit 023b1db into astral-sh:main Jul 28, 2026
46 checks passed
@astral-sh-bot

astral-sh-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document lint.flake8-import-conventions.extend-aliases as being able to somewhat revert a default alias / enforce non-aliased

2 participants