#11813·pyright

Identity aliases not handled properly

Author: Moussa-MikhailCreated Oct 1, 2026Updated Oct 1, 2026
Labelsbug

Identity aliases (type Identity[T] = T) are not handled properly in validateTypeVarUsage leading to two different bugs. This issue also affects Annotated[T, ""].

  1. When used to annotate an attribute T isn't found in the scope of the class or its enclosing classes', so it's rejected with the (misleading) "scoped to local method" error.
  2. If an enclosing scope has a TypeVar with the same name as the one used in Identity's definition then T@Identity is incorrectly marked as bound so alias specialization never substitutes the subscript argument into it, and Identity[int] evaluates to T@Identity instead of int.

Playground

python
type Identity[T] = T

class Box:
    def __init__(self) -> None:
        self.x: Identity[list[int]] = [] # Attribute type cannot use type variable "T@Identity" scoped to local method

def name_collision[T: int](x: T):
    a: Identity[int] = x # Type "T@name_collision" is not assignable to declared type "T@Identity"