Skip to content

Mypy thinks dict[Never, Never] is a subtype of Mapping[str, object] #19641

Description

@randolf-scholz

This behaves as expected: https://mypy-play.net/?mypy=latest&python=3.12&gist=8718e96550599dc3ae48a13879005762

from typing import Mapping, Never

def upcast(d: dict[Never, Never]) -> Mapping[str, object]:
    return d  # E: [return-value] (✅ expected)

But it breaks here (due to caching?) https://mypy-play.net/?mypy=latest&python=3.12&gist=6199ba50b6b02e2350e70cb3a8ff4bba

from typing import Mapping, Never

def get[M: Mapping[str, object]](arg: M, /) -> M:
    return arg

reveal_type(get({}))  # dict[Never, Never] (❌ incorrect)

def upcast(d: dict[Never, Never]) -> Mapping[str, object]:
    return d  # <-- No error anymore 😱

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions