Skip to content

More specific inline dict type inference can fail on 1.17.0 #19474

@markhobson

Description

@markhobson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions