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

dict considered incompatible with dict type with supertype for key #15030

Closed
jwodder opened this issue Apr 10, 2023 · 1 comment
Closed

dict considered incompatible with dict type with supertype for key #15030

jwodder opened this issue Apr 10, 2023 · 1 comment
Labels
bug mypy got something wrong

Comments

@jwodder
Copy link

jwodder commented Apr 10, 2023

Bug Report

Consider the following code:

from pathlib import Path

def mkfiles(spec: dict[str | Path, str]) -> None:
    ...

spec: dict[str, str] = {
    "foo.txt": "Fooey",
    "bar.txt": "Bar-y",
}

mkfiles(spec)

Running mypy on this code with the default options produces the following error:

superkey01.py:11: error: Argument 1 to "mkfiles" has incompatible type "Dict[str, str]"; expected "Dict[Union[str, Path], str]"  [arg-type]

Changing dict to collections.abc.Mapping does not get rid of the error.

Expected Behavior

mypy should have accepted the code, as the key type str | Path is more general than str.

Your Environment

  • Mypy version used: 1.2.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.3 on macOS 11.7.2
@jwodder jwodder added the bug mypy got something wrong label Apr 10, 2023
@JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 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