mypy
mypy copied to clipboard
Combining an `or` and `dict.get` results in the wrong inferred type.
Bug Report
Combining an or and dict.get results in the wrong inferred type.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=8ac5004cd4094219a0f090ebd0d34777
Expected Behavior
The or_dict method in the gist above should type check as valid.
Actual Behavior
mypy thinks that the return type should be str | None
Your Environment
- Mypy version used: 0.991
- Mypy command-line flags: tried with both
--strictand without - Mypy configuration options from
mypy.ini(and other config files): none, see mypy-play link - Python version used: 3.11
return bar if bar else d.get("bar", "baz") correct
return bar or d.get("bar", "baz") wrong
I wonder why the short circuit evaluation is treated differently