Cannot call dict.get with a falsy second argument and an 'or' expression.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
In mypy 0.610, as well as the latest version from master, the following throws an error under Python 3.6
def foo(a: str):
pass
d = {'key': 'a'}
foo(d.get('key', None) or '26')
test.py:6: error: Argument 2 to "get" of "Mapping" has incompatible type "None"; expected "str"
However, no matter what, foo will still receive a str, given that None is falsy. Therefore, no error should be thrown. This occurs with just a simple call to mypy foo.py with no flags.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproduction in test.py and run it with mypy foo.py under Python 3.6. Trace how the type checker handles Mapping.get when its result is used in the shown or expression. Done means the example no longer reports an incompatible None argument while preserving appropriate type checking for similar calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100