From c247d63cf985c2221d3969aefd05eb7d9278f7a5 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 21 Apr 2022 23:57:52 +0100 Subject: [PATCH] Add test case for fixed bug regarding nested generic classes --- test-data/unit/check-generics.test | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 6a89f6fb200c..b228e76a32d1 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -1506,6 +1506,22 @@ class Outer(Generic[T]): def g(self) -> None: y: T # E: Invalid type "__main__.T" +[case testGenericClassInsideOtherGenericClass] +from typing import TypeVar, Generic +T = TypeVar("T") +K = TypeVar("K") + +class C(Generic[T]): + def __init__(self, t: T) -> None: ... + class F(Generic[K]): + def __init__(self, k: K) -> None: ... + def foo(self) -> K: ... + +reveal_type(C.F(17).foo()) # N: Revealed type is "builtins.int" +reveal_type(C("").F(17).foo()) # N: Revealed type is "builtins.int" +reveal_type(C.F) # N: Revealed type is "def [K] (k: K`1) -> __main__.C.F[K`1]" +reveal_type(C("").F) # N: Revealed type is "def [K] (k: K`1) -> __main__.C.F[K`1]" + -- Callable subtyping with generic functions -- -----------------------------------------