You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is another one of the many "join-vs-union" behavioural peculiarities that mypy has: in many situations, mypy prefers to infer a type as being a common supertype rather than a union. Here, it sees that some values in the dictionary are str, and others are dict[str, object], so infers Collection[str], since this is indeed a common supertype of str and dict[str, object] according to the definitions in typeshed.
We already have many join-vs-union issues open, and I don't really think we need another, so I'm going to close this out. Follow #12056 for discussion on possibly changing mypy's behaviour here :)
Bug Report
Whilst working on HomeAssistant PR, found this weird behavior where the type inferred from a dict is completely wrong.
home-assistant/core#82853
To Reproduce
Expected Behavior
I would have expected the value type to be
dict[str, str | dict]
, or maybedict[str, Any]
Actual Behavior
Revealed type is
builtins.dict[builtins.str, typing.Collection[builtins.str]]
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: