Type Inference on dict-literals with values of Optional[Any]
ignores non-optional values.
#9544
Labels
bug
mypy got something wrong
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
If a dict literal contains a value of type
Optional[Any]
, other optional values (e.g.Optional[T1]
,Optional[T2]
), and non optional (non-overlapping) values (e.g.T3
,T4
), then its inferred type isdict[KeyType*, Union[T1, None, T2]]
ignoringAny
,T3
, andT4
.To Reproduce
Output from mypy is:
Expected Behavior
I would've expected the inferred type of
my_dict
to bedict[str*, Union[Any, str, None, int, Decimal, datetime]]
Or just reduce to
dict[str*, object*]
Your Environment
--show-error-codes
I can work around this quite easily (by either
type: ignore
, orcast
on theAny
) But thought I'd raise it in case this isn't expected behaviour.The text was updated successfully, but these errors were encountered: