Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4199,7 +4199,19 @@ def check_multi_assignment_from_tuple(
# inferred return type for an overloaded function
# to be ambiguous.
return
assert isinstance(reinferred_rvalue_type, TupleType)
if not isinstance(reinferred_rvalue_type, TupleType):
# Using outer context may transform a tuple type into something
# else when the callee is overloaded. Recheck with the new result
# and bail out.
self.check_multi_assignment(
lvalues,
rvalue,
context,
rv_type=reinferred_rvalue_type,
infer_lvalue_type=infer_lvalue_type,
undefined_rvalue=undefined_rvalue,
)
return
rvalue_type = reinferred_rvalue_type

left_rv_types, star_rv_types, right_rv_types = self.split_around_star(
Expand Down
16 changes: 16 additions & 0 deletions test-data/unit/check-inference-context.test
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ class A(Generic[T]): pass
class B: pass
[out]

[case testInferUnpackedOverloadWithTupleAndOtherReturns]
# https://github.com/python/mypy/issues/19920
from typing import Tuple, TypeVar, overload

_T = TypeVar("_T")

@overload # type: ignore[no-overload-impl]
def gather(f1: _T) -> Tuple[_T]: ...
@overload
def gather(*fns: object) -> int: ...

def crash() -> None:
foo: str
(foo,) = gather(0) # E: "int" object is not iterable
[builtins fixtures/tuple.pyi]

[case testInferMultipleLocalVariableTypesWithArrayRvalueAndNesting]
from typing import TypeVar, List, Generic
T = TypeVar('T')
Expand Down
Loading