Skip to content

Commit 14c6877

Browse files
aterazilevkivskyi
authored andcommitted
Handle class with tuple base as TypeVar bound (#7444)
Fixes #7427
1 parent 69ca176 commit 14c6877

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

mypy/checkmember.py

+2
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ def analyze_type_type_member_access(name: str,
261261
upper_bound = get_proper_type(typ.item.upper_bound)
262262
if isinstance(upper_bound, Instance):
263263
item = upper_bound
264+
elif isinstance(upper_bound, TupleType):
265+
item = tuple_fallback(upper_bound)
264266
elif isinstance(typ.item, TupleType):
265267
item = tuple_fallback(typ.item)
266268
elif isinstance(typ.item, FunctionLike) and typ.item.is_type_obj():

test-data/unit/check-bound.test

+13
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ def f(x: T) -> int:
169169
[builtins fixtures/classmethod.pyi]
170170

171171

172+
[case testBoundClassMethodWithNamedTupleBase]
173+
from typing import NamedTuple, Type, TypeVar
174+
class A(NamedTuple):
175+
@classmethod
176+
def foo(cls) -> None: ...
177+
178+
T = TypeVar('T', bound=A)
179+
def f(x: Type[T]) -> None:
180+
reveal_type(x.foo) # N: Revealed type is 'def ()'
181+
x.foo()
182+
[builtins fixtures/classmethod.pyi]
183+
184+
172185
[case testBoundStaticMethod]
173186
from typing import TypeVar
174187
class A0:

0 commit comments

Comments
 (0)