Skip to content

Commit 9a776cf

Browse files
committed
fix
1 parent 45a7851 commit 9a776cf

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

mypy/subtypes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ def visit_instance(self, left: Instance) -> bool:
467467
if mapped.type.fullname == right.partial_fallback.type.fullname:
468468
if all(isinstance(get_proper_type(a), AnyType) for a in mapped.args):
469469
return not self.proper_subtype
470+
if mapped.type.tuple_type:
471+
expanded = expand_type_by_instance(mapped.type.tuple_type, mapped)
472+
assert isinstance(expanded, TupleType)
473+
if self._is_subtype(
474+
expanded,
475+
right.copy_modified(fallback=expanded.partial_fallback)
476+
):
477+
return not self.proper_subtype
470478
return False
471479
if isinstance(right, TypeVarTupleType):
472480
# tuple[Any, ...] is like Any in the world of tuples (see special case above).

test-data/unit/check-tuples.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,8 +1444,7 @@ T = TypeVar('T')
14441444
def foo(o: CallableTuple[int]) -> int:
14451445
reveal_type(o) # N: Revealed type is "Tuple[builtins.str, builtins.int, fallback=__main__.CallableTuple[builtins.int]]"
14461446
reveal_type(o.count(3)) # N: Revealed type is "builtins.int"
1447-
# TODO: incorrect error below
1448-
return o(1, 2) # E: Invalid self argument "CallableTuple[int]" to attribute function "__call__" with type "Callable[[CallableTuple[T], int, int], int]"
1447+
return o(1, 2)
14491448

14501449
class CallableTuple(Tuple[str, T]):
14511450
def __call__(self, n: int, m: int) -> int:

0 commit comments

Comments
 (0)