@@ -569,3 +569,51 @@ class Base:
569569 @classmethod
570570 def make(cls: Type[T], num: int) -> Tuple[T, ...]: ...
571571[builtins fixtures/classmethod.pyi]
572+
573+ [case testSelfTypeClassMethodOnUnion]
574+ from typing import Type, Union, TypeVar
575+
576+ T = TypeVar('T')
577+
578+ class A:
579+ @classmethod
580+ def meth(cls: Type[T]) -> T: ...
581+ class B(A): ...
582+ class C(A): ...
583+
584+ t: Type[Union[B, C]]
585+ reveal_type(t.meth) # N: Revealed type is 'Union[def () -> __main__.B*, def () -> __main__.C*]'
586+ x = t.meth()
587+ reveal_type(x) # N: Revealed type is 'Union[__main__.B*, __main__.C*]'
588+ [builtins fixtures/classmethod.pyi]
589+
590+ [case testSelfTypeClassMethodOnUnionGeneric]
591+ from typing import Type, Union, TypeVar, Generic
592+
593+ T = TypeVar('T')
594+ S = TypeVar('S')
595+
596+ class A(Generic[T]):
597+ @classmethod
598+ def meth(cls: Type[S]) -> S: ...
599+
600+ t: Type[Union[A[int], A[str]]]
601+ x = t.meth()
602+ reveal_type(x) # N: Revealed type is 'Union[__main__.A*[builtins.int], __main__.A*[builtins.str]]'
603+ [builtins fixtures/classmethod.pyi]
604+
605+ [case testSelfTypeClassMethodOnUnionList]
606+ from typing import Type, Union, TypeVar, List
607+
608+ T = TypeVar('T')
609+
610+ class A:
611+ @classmethod
612+ def meth(cls: Type[T]) -> List[T]: ...
613+ class B(A): ...
614+ class C(A): ...
615+
616+ t: Type[Union[B, C]]
617+ x = t.meth()[0]
618+ reveal_type(x) # N: Revealed type is 'Union[__main__.B*, __main__.C*]'
619+ [builtins fixtures/isinstancelist.pyi]
0 commit comments