Closed
Description
Passing an overly-general Union to dict.get, like this:
from typing import Union
x = 5 # type: Union[int, str]
{ 1: 1 }.get(x, 0)
results in this error:
test.py:4: error: Argument 1 to "get" of "dict" has incompatible type "Union[int, str]"; expected "int"
Arguably, this should be allowed, because get
provides a default if the item is not found (unlike __getitem__
). But by that logic, potentially any type should be a valid argument to get
, which doesn't seem right.
@gvanrossum: further thoughts?