Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive when assigning an empty dict to a union of dicts or Mappings #16044

Closed
hamdanal opened this issue Sep 4, 2023 · 1 comment
Closed
Labels
bug mypy got something wrong

Comments

@hamdanal
Copy link
Collaborator

hamdanal commented Sep 4, 2023

Bug Report

Like the title says.
I thought it might be because of dict variance but mapping union errors as well.

To Reproduce

from collections.abc import Mapping

d1: dict[str, str] | dict[int, int] = {}
d2: Mapping[str, str] | Mapping[int, int] = {}

reveal_type(d1)
reveal_type(d2)

Expected Behavior

No errors.

Actual Behavior

$ mypy t.py
t.py:3: error: Incompatible types in assignment (expression has type "dict[<nothing>, <nothing>]", variable has type "dict[str, str] | dict[int, int]")  [assignment]
t.py:4: error: Incompatible types in assignment (expression has type "dict[<nothing>, <nothing>]", variable has type "Mapping[str, str] | Mapping[int, int]")  [assignment]
t.py:6: note: Revealed type is "Union[builtins.dict[builtins.str, builtins.str], builtins.dict[builtins.int, builtins.int]]"
t.py:7: note: Revealed type is "Union[typing.Mapping[builtins.str, builtins.str], typing.Mapping[builtins.int, builtins.int]]"

Your Environment

  • Mypy version used: mypy 1.5.1 (compiled: yes)
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.10
@hamdanal hamdanal added the bug mypy got something wrong label Sep 4, 2023
@ilevkivskyi
Copy link
Member

A duplicate of #6463

@ilevkivskyi ilevkivskyi closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants