[ty] Add unbound type variable detection in annotations by AlexWaygood · Pull Request #23641 · astral-sh/ruff (original) (raw)

@AlexWaygood added the ty

Multi-file analysis & type inference

label

Mar 1, 2026

dcreager

@claude @AlexWaygood

… their bound scope

This adds validation for three missing checks around correct use of type variables:

  1. Reject unbound type variables in module-scope annotations (e.g., x: T)
  2. Reject unbound type variables in function/class bodies where they aren't part of the enclosing generic context (e.g., S inside def f(x: T))
  3. Reject type variables from outer class scopes used in inner class bodies (e.g., class C[T]: class Bad: x: T)

The implementation:

https://claude.ai/code/session_01FUqdwkfw72xwPnuhqqpvp6

@claude @AlexWaygood

@claude @AlexWaygood

@AlexWaygood

@AlexWaygood

@AlexWaygood @dcreager

Co-authored-by: Douglas Creager dcreager@dcreager.net

@carljm carljm removed their request for review

March 2, 2026 15:55

@AlexWaygood AlexWaygood deleted the claude/add-type-variable-validation-pw9Ns branch

March 2, 2026 16:01

carljm added a commit that referenced this pull request

Mar 2, 2026

@carljm

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})