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
In my opinion, this is basically the textbook case of using a non-Literal in a Literal context.
In other words, the Literal here can only be a str, so mypy shouldn't error on the keys type compatibility.
Actual Behavior
Here's the output of mypy:
path/to/literal_and_dict.py: note: In function "get_some_dict":
path/to/literal_and_dict.py:8:12: error: Incompatible return value type (got "Dict[Union[Literal['foo'], Literal['bar']], Any]", expected "Dict[str, Any]") [return-value]
jamesbraza
changed the title
Using non-Literals in Literal contexts not working (false positive error)
Using non-Literals in Literal contexts not working when used as Dict key (false positive error)
Jan 12, 2021
Bug Report
Before I begin, I would like to say that I am a big fan of PEP 586's
Literal
type.To Reproduce
Here is some sample code that exposes (what I believe is) a break from Using non-Literals in Literal contexts part of PEP 586.
Expected Behavior
In my opinion, this is basically the textbook case of using a non-Literal in a Literal context.
In other words, the
Literal
here can only be astr
, so mypy shouldn't error on the keys type compatibility.Actual Behavior
Here's the output of mypy:
Your Environment
master
0.800+dev.3497675c5f7917eb0e8ad4b7e2b7f3bc4cfd52dcmypy.ini
(and other config files): none notableThe text was updated successfully, but these errors were encountered: