Skip to content

mypy assigns dict[Never, Never] to TypeVar bound by dict[str, object] #19895

Description

@randolf-scholz

https://mypy-play.net/?mypy=1.18.2&python=3.12&gist=2e756ebb6f05cb8ef01bcc4cb504c147

def get[D: dict[str, object]](arg: D, /) -> D:
    return arg

reveal_type(get({}))  # N: Revealed type is "builtins.dict[Never, Never]"

This is incorrect, since dict[Never, Never] is not a subtype of dict[str, object]. The solution should have key type str (or Any), but not Never.

See Also: #19641, but this was closed since the caching part of the problem was addressed

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