Skip to content

Commit 292890a

Browse files
committed
Add TypeVar tests
1 parent 29f186c commit 292890a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

test-data/unit/check-classes.test

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8595,17 +8595,20 @@ import enum as __enum
85958595
class C(__enum.Flag): ...
85968596

85978597
[case testNameManglingAnnotationsPast]
8598+
from typing import Generic, TypeVar
85988599

8599-
class A:
8600-
__x: int
8600+
__T = TypeVar("__T")
8601+
8602+
class A(Generic[__T]):
8603+
__x: __T # E: Name "_A__T" is not defined
86018604

86028605
__y = int
86038606
class __B:
8604-
def f1(self, a: A) -> __y: # E: Name "_B__y" is not defined
8605-
a.__x # E: "A" has no attribute "_B__x"; maybe "_A__x"?
8607+
def f1(self, a: A[int]) -> __y: # E: Name "_B__y" is not defined
8608+
a.__x # E: "A[int]" has no attribute "_B__x"; maybe "_A__x"?
86068609

86078610
def f2(self, a: A) -> "__y":
8608-
a.__x # E: "A" has no attribute "_B__x"; maybe "_A__x"?
8611+
a.__x # E: "A[Any]" has no attribute "_B__x"; maybe "_A__x"?
86098612
return 1
86108613

86118614
class C:
@@ -8623,18 +8626,20 @@ reveal_type(C().b2) # N: Revealed type is "__main__.__B"
86238626

86248627
[case testNameManglingAnnotationsFuture]
86258628
from __future__ import annotations
8629+
from typing import Generic, TypeVar
86268630

8627-
class A:
8628-
__x: int
8631+
__T = TypeVar("__T")
8632+
class A(Generic[__T]):
8633+
__x: __T
86298634

86308635
__y = int
86318636
class __B:
8632-
def f1(self, a: A) -> __y:
8633-
a.__x # E: "A" has no attribute "_B__x"; maybe "_A__x"?
8637+
def f1(self, a: A[int]) -> __y:
8638+
a.__x # E: "A[int]" has no attribute "_B__x"; maybe "_A__x"?
86348639
return 1
86358640

86368641
def f2(self, a: A) -> "__y":
8637-
a.__x # E: "A" has no attribute "_B__x"; maybe "_A__x"?
8642+
a.__x # E: "A[Any]" has no attribute "_B__x"; maybe "_A__x"?
86388643
return 1
86398644

86408645
class C:

0 commit comments

Comments
 (0)