More specific inline dict type inference can fail on 1.17.0
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
More specific inline dict type inference can fail on 1.17.0.
To Reproduce
The following fails on 1.17.0 but is fine on 1.16.1 (the playground link uses master as 1.17.0 isn't available there):
https://mypy-play.net/?mypy=master&python=3.13&gist=7e77b89fe5f9cb7e548c4ef83b3783c1
Revealing the type for the inline dict gives:
- 1.16.1:
builtins.dict[builtins.str, Union[typing.Collection[builtins.str], None]] - 1.17.0:
builtins.dict[builtins.str, builtins.dict[builtins.str, builtins.list[Any] | None] | builtins.dict[builtins.str, builtins.str] | builtins.str | None]
Expected Behavior
No mypy errors.
Actual Behavior
main.py:11: error: Dict entry 0 has incompatible type "str": "None"; expected "str": "str" [dict-item]
main.py:12: error: Dict entry 1 has incompatible type "str": "list[Never]"; expected "str": "str" [dict-item]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.17.0
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.13.5
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 linked mypy playground reproduction and compare its behavior on 1.16.1, 1.17.0, and master. The issue names no repository file or test, so trace the inline dictionary type-inference path from the reproduced errors; done means the example produces no errors while preserving the expected inferred type.
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
- Mostly clear
- Newbie friendliness
- 42/100