-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
Description
While working on #11128 I got hit by this.
This code does not type check:
from typing import TypeVar, Union, List
T1 = TypeVar("T1")
def promote_list(item: Union[T1, List[T1]]) -> List[T1]:
...
exprs: List[int]
reveal_type(promote_list(exprs)) # error
# ex.py:9: note: Revealed type is "builtins.list[<nothing>]"
# ex.py:9: error: Argument 1 to "promote_list" has incompatible type "List[int]"; expected "List[<nothing>]"
reveal_type(promote_list(1)) # ok
# Revealed type is "builtins.list[builtins.int*]"
Which is not what I expect. For example, TypeScript solves this properly:
function protomoteList<T>(input: T | T[]): T[] {
return []
}
function test(input: number[]) {}
test(protomoteList(1)) # ok
Cause
It happens somewhere here:
Lines 168 to 171 in b3ff2a6
return any_constraints( | |
[infer_constraints_if_possible(t_item, actual, direction) | |
for t_item in template.items], | |
eager=False) |
I will try to solve this, but I know that this is going to be complicated.