Skip to content

[flake8-tidy-imports] Add extend-banned-api - #28644

Merged
charliermarsh merged 3 commits into
mainfrom
charlie/codex-extend-banned-api
Sep 16, 2026
Merged

charliermarsh merged 3 commits into
mainfrom
charlie/codex-extend-banned-api

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Add lint.flake8-tidy-imports.extend-banned-api so we can add banned APIs without repeating an inherited banned-api table. Entries in extend-banned-api override entries with the same key in banned-api, including their diagnostic messages.

For example, a child ruff.toml can add a ban while retaining the bans from its base configuration:

extend = "../ruff.toml"

[lint.flake8-tidy-imports.extend-banned-api]
"typing.TypedDict".msg = "Use typing_extensions.TypedDict instead."

This follows the existing extend-aliases behavior: the base and extension tables inherit independently, and we merge them after resolving configuration inheritance. A child can replace either table, or clear it with {}. The change includes option documentation, the generated JSON schema, and CLI coverage for standalone bans, inheritance, message overrides, and clearing either table.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre September 16, 2026 11:23
@astral-sh-bot

astral-sh-bot Bot commented Sep 16, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser

MichaReiser commented Sep 16, 2026

Copy link
Copy Markdown
Member

-extend everything 😭. Seems like a reasonable one off fix.

@MichaReiser MichaReiser added the configuration Related to settings and configuration label Sep 16, 2026

@MichaReiser MichaReiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. Good luck teaching codex Rust multiline strings and what dedent is

Comment thread crates/ruff/tests/cli/lint.rs Outdated
Comment on lines +628 to +629

assert_cmd_snapshot!(fixture.check_command());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the snapshots are small enough that they can be inline snapshots (which is what we now mainly use for tests)

Comment thread crates/ruff/tests/cli/lint.rs Outdated
fixture.write_file("child/nested/ruff.toml", "extend = \"../ruff.toml\"\n")?;
fixture.write_file(
"child/nested/test.py",
"import cgi\nimport pipes\nfrom typing import Any, TypedDict\n",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My biggest annoyance with codex right now. Can you ask it to pretty please use rust multiline strings instead of squeezing every file on a single line (I believe write_file even calls dedent for you)

Comment thread crates/ruff/tests/cli/lint.rs Outdated
Comment on lines +657 to +661
extend = "../ruff.toml"

[lint.flake8-tidy-imports.extend-banned-api]
"cgi".msg = "Use a supported library instead."
"typing.TypedDict".msg = "Use typing_extensions.TypedDict instead."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't believe the indent here is necessary. Isn't CliTest calling dedent?

@charliermarsh
charliermarsh enabled auto-merge (squash) September 16, 2026 13:03
@charliermarsh
charliermarsh merged commit fe9f065 into main Sep 16, 2026
49 checks passed
@charliermarsh
charliermarsh deleted the charlie/codex-extend-banned-api branch September 16, 2026 13:05
carljm added a commit that referenced this pull request Sep 16, 2026
…aliases

* origin/main:
  Bump version to 0.16.8 (#28648)
  [ty] Bound aliased intersection expansion during inference (#28546)
  renovate: update uv hashes correctly with setup-uv (#28621)
  [ty] Compact reachable binding and declaration histories (#28349)
  [ty] Avoid storing constraint nodes twice (#28375)
  [ty] Compare bound-method receivers before signatures (#28384)
  [`flake8-type-checking`] Prefer lazy imports over `TYPE_CHECKING` on 3.15+ (`TC001`, `TC002`, `TC003`) (#28541)
  [ty] Watch script dependencies in CLI watch mode (#28125)
  [flake8-tidy-imports] Add `extend-banned-api` (#28644)
  [ty] Support `type[A & B]` (#27124)

# Conflicts:
#	crates/ty_python_semantic/src/types/set_theoretic/builder.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Related to settings and configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants