File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -923,10 +923,10 @@ def is_type_obj(self) -> bool:
923
923
def type_object (self ) -> mypy .nodes .TypeInfo :
924
924
assert self .is_type_obj ()
925
925
ret = self .ret_type
926
- if isinstance (ret , TupleType ):
927
- ret = ret .partial_fallback
928
926
if isinstance (ret , TypeVarType ):
929
927
ret = ret .upper_bound
928
+ if isinstance (ret , TupleType ):
929
+ ret = ret .partial_fallback
930
930
assert isinstance (ret , Instance )
931
931
return ret .type
932
932
Original file line number Diff line number Diff line change @@ -828,3 +828,21 @@ class Child(Base):
828
828
829
829
Base(param=10)
830
830
Child(param=10)
831
+
832
+ [case testNamedTupleClassMethodWithGenericReturnValue]
833
+ from typing import TypeVar, Type, NamedTuple
834
+
835
+ T = TypeVar('T', bound='Parent')
836
+
837
+ class Parent(NamedTuple):
838
+ x: str
839
+
840
+ @classmethod
841
+ def class_method(cls: Type[T]) -> T:
842
+ return cls(x='text')
843
+
844
+ class Child(Parent):
845
+ pass
846
+
847
+ reveal_type(Child.class_method()) # E: Revealed type is 'Tuple[builtins.str, fallback=__main__.Child]'
848
+ [builtins fixtures/classmethod.pyi]
You can’t perform that action at this time.
0 commit comments