Skip to content

[flake8-type-checking] Add unquoted-type-checking-only-import (TC200)#25203

Open
anishgirianish wants to merge 1 commit into
astral-sh:mainfrom
anishgirianish:tc200-unquoted-type-checking-only-import
Open

[flake8-type-checking] Add unquoted-type-checking-only-import (TC200)#25203
anishgirianish wants to merge 1 commit into
astral-sh:mainfrom
anishgirianish:tc200-unquoted-type-checking-only-import

Conversation

@anishgirianish
Copy link
Copy Markdown
Contributor

@anishgirianish anishgirianish commented May 17, 2026

Summary

Adds TC200 (unquoted-type-checking-only-import), which flags annotation references to imports defined only inside if TYPE_CHECKING: blocks. The fix wraps the annotation in quotes via the existing quote_annotation helper.

Naturally silent on:

  • local variable annotations
  • from __future__ import annotations files
  • Python 3.14+ (PEP 649 defers annotations by default)

Defers to TC004 when both rules are enabled to avoid fix circulation, same pattern as TC007 ↔ TC004.

Closes #5753.

Test plan

  • Fixture covers function params/return, module-level AnnAssign, class body, subscripts, unions, attribute access, parenthesized and multi-line annotations, already-quoted (triple-quoted included).
  • PEP 649 silence verified via an empty-snapshot test pinned to the default target version.
  • TC004 coordination verified via a dedicated test.

@astral-sh-bot astral-sh-bot Bot requested a review from ntBre May 17, 2026 04:18
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 17, 2026

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature-request] Detect invalid unquoted imports

2 participants