File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -4199,7 +4199,19 @@ def check_multi_assignment_from_tuple(
41994199 # inferred return type for an overloaded function
42004200 # to be ambiguous.
42014201 return
4202- assert isinstance (reinferred_rvalue_type , TupleType )
4202+ if not isinstance (reinferred_rvalue_type , TupleType ):
4203+ # Using outer context may transform a tuple type into something
4204+ # else when the callee is overloaded. Recheck with the new result
4205+ # and bail out.
4206+ self .check_multi_assignment (
4207+ lvalues ,
4208+ rvalue ,
4209+ context ,
4210+ rv_type = reinferred_rvalue_type ,
4211+ infer_lvalue_type = infer_lvalue_type ,
4212+ undefined_rvalue = undefined_rvalue ,
4213+ )
4214+ return
42034215 rvalue_type = reinferred_rvalue_type
42044216
42054217 left_rv_types , star_rv_types , right_rv_types = self .split_around_star (
Original file line number Diff line number Diff line change @@ -126,6 +126,22 @@ class A(Generic[T]): pass
126126class B: pass
127127[out]
128128
129+ [case testInferUnpackedOverloadWithTupleAndOtherReturns]
130+ # https://github.com/python/mypy/issues/19920
131+ from typing import Tuple, TypeVar, overload
132+
133+ _T = TypeVar("_T")
134+
135+ @overload # type: ignore[no-overload-impl]
136+ def gather(f1: _T) -> Tuple[_T]: ...
137+ @overload
138+ def gather(*fns: object) -> int: ...
139+
140+ def crash() -> None:
141+ foo: str
142+ (foo,) = gather(0)
143+ [builtins fixtures/tuple.pyi]
144+
129145[case testInferMultipleLocalVariableTypesWithArrayRvalueAndNesting]
130146from typing import TypeVar, List, Generic
131147T = TypeVar('T')
You can’t perform that action at this time.
0 commit comments