File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1717 TypeOfAny ,
1818 TypeVarTupleType ,
1919 UnpackType ,
20+ UnionType ,
2021 get_proper_type ,
2122)
2223
@@ -211,6 +212,18 @@ def expand_actual_type(
211212 # Just return `Any`, other parts of code would raise
212213 # a different error for improper use.
213214 return AnyType (TypeOfAny .from_error )
215+ elif isinstance (actual_type , UnionType ):
216+ item_types = [
217+ self .expand_actual_type (
218+ item ,
219+ actual_kind = actual_kind ,
220+ formal_name = formal_name ,
221+ formal_kind = formal_kind ,
222+ allow_unpack = allow_unpack ,
223+ )
224+ for item in actual_type .items
225+ ]
226+ return UnionType .make_union (item_types )
214227 elif isinstance (actual_type , TupleType ):
215228 # Get the next tuple item of a tuple *arg.
216229 if self .tuple_index >= len (actual_type .items ):
Original file line number Diff line number Diff line change @@ -3708,3 +3708,20 @@ foo(*args) # E: Argument 1 to "foo" has incompatible type "*list[object]"; expe
37083708kwargs: dict[str, object]
37093709foo(**kwargs) # E: Argument 1 to "foo" has incompatible type "**dict[str, object]"; expected "P"
37103710[builtins fixtures/dict.pyi]
3711+
3712+ [case testUnpackUnionStarArgs]
3713+ from __future__ import annotations
3714+ from typing import TypeVar
3715+ T = TypeVar("T")
3716+
3717+ def f(*args: T) -> T: ...
3718+
3719+ def star_union_list(x: list[str | None] | list[str]):
3720+ reveal_type([*x]) # N: Revealed type is "builtins.list[Union[builtins.str, None]]"
3721+ reveal_type(f(*x)) # N: Revealed type is "Union[builtins.str, None]"
3722+
3723+ def star_union_list_tuple(x: list[str | None] | tuple[int, int]):
3724+ reveal_type([*x]) # N: Revealed type is "builtins.list[Union[builtins.str, None, builtins.int]]"
3725+ reveal_type(f(*x)) # N: Revealed type is "Union[builtins.str, None, builtins.int]"
3726+
3727+ [builtins fixtures/tuple.pyi]
You can’t perform that action at this time.
0 commit comments