Skip to content

Invalid type revealed when type var uses another type var as default #20027

@sobolevn

Description

@sobolevn
from typing import TypeVar, Generic

X = TypeVar('X')
Y = TypeVar('Y', default=X)
Z = TypeVar('Z', default=Y)

class A(Generic[X, Y, Z]):
    x: X
    y: Y
    z: Z

a1: A[int]
reveal_type(a1.x)  # N: Revealed type is "builtins.int"
reveal_type(a1.y)  # N: Revealed type is "builtins.int"
reveal_type(a1.z)  # N: Revealed type is "X`1"

a1.z must be revealed as int as well, not as X'1

Refs #20021

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions