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

list of dict is reported as not compatible with list of Mapping #17752

Closed
Czaki opened this issue Sep 9, 2024 · 1 comment
Closed

list of dict is reported as not compatible with list of Mapping #17752

Czaki opened this issue Sep 9, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@Czaki
Copy link

Czaki commented Sep 9, 2024

Bug Report

Then have a function that returns a list of dicts and assigns it to a variable annotated as list of Mapping the mypy reports error, however when change annotation to Sequence[Mapping] it works.

To Reproduce

Code that generates mypy warning

from collections.abc import Mapping, Sequence


def get_dkt() -> list[dict]:
    return [{}]
    
var2: list[Mapping]

var2 = get_dkt()

code that do not generate error:

from collections.abc import Mapping, Sequence


def get_dkt() -> list[dict]:
    return [{}]
    
var2: Sequence[Mapping]

var2 = get_dkt()

https://mypy-play.net/?mypy=latest&python=3.12&gist=a3a7cf085ceed0a395392a6adaa74a29

Expected Behavior

Both presented type annotation above should work.

Actual Behavior

Your Environment

  • Mypy version used: 1.11.2
  • Python version used: 3.12
@JelleZijlstra
Copy link
Member

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