Skip to content

Inconsistent behavior when matching dict against Mapping | Hashable #12467

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

Closed
twoertwein opened this issue Mar 27, 2022 · 1 comment
Closed
Labels
bug mypy got something wrong

Comments

@twoertwein
Copy link

Bug Report

Mypy does not match dict[int, int] with Mapping[Hashable, Any] when it is in Union[Mapping[Hashable, Any], Hashable] but it matches when Mapping[Hashable, Any] is by itself.

To Reproduce

Example from @Dr-Irv:

from typing import Mapping, Hashable, Any, Union

def myfun(m: Mapping[Hashable, Any]):
    ...

def myfun2(m: Union[Mapping[Hashable, Any], Hashable]):
    ...

myfun({1: 1})  # passes
myfun2({1: 1})  # errors

Expected Behavior

No error.

Actual Behavior

error: Argument 1 to "myfun2" has incompatible type "Dict[int, int]"; expected "Union[Mapping[Hashable, Any], Hashable]"
note: Following member(s) of "Dict[int, int]" have conflicts:
note:     __hash__: expected "Callable[[], int]", got "None"

No error with pyright.

Your Environment

  • Mypy version used: 0.942
@twoertwein twoertwein added the bug mypy got something wrong label Mar 27, 2022
@twoertwein
Copy link
Author

Didn't see #12464

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

1 participant