Skip to content

Commit 09dbdf6

Browse files
authored
Add test case for fixed bug regarding nested generic classes (#12652)
Closes #5551 (the bug in that issue was fixed by #12590)
1 parent 6eac240 commit 09dbdf6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test-data/unit/check-generics.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,22 @@ class Outer(Generic[T]):
15061506
def g(self) -> None:
15071507
y: T # E: Invalid type "__main__.T"
15081508

1509+
[case testGenericClassInsideOtherGenericClass]
1510+
from typing import TypeVar, Generic
1511+
T = TypeVar("T")
1512+
K = TypeVar("K")
1513+
1514+
class C(Generic[T]):
1515+
def __init__(self, t: T) -> None: ...
1516+
class F(Generic[K]):
1517+
def __init__(self, k: K) -> None: ...
1518+
def foo(self) -> K: ...
1519+
1520+
reveal_type(C.F(17).foo()) # N: Revealed type is "builtins.int"
1521+
reveal_type(C("").F(17).foo()) # N: Revealed type is "builtins.int"
1522+
reveal_type(C.F) # N: Revealed type is "def [K] (k: K`1) -> __main__.C.F[K`1]"
1523+
reveal_type(C("").F) # N: Revealed type is "def [K] (k: K`1) -> __main__.C.F[K`1]"
1524+
15091525

15101526
-- Callable subtyping with generic functions
15111527
-- -----------------------------------------

0 commit comments

Comments
 (0)