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

Hashable and None have overlapping type in mypy >= 0.981 #13805

Closed
headtr1ck opened this issue Oct 3, 2022 · 1 comment
Closed

Hashable and None have overlapping type in mypy >= 0.981 #13805

headtr1ck opened this issue Oct 3, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@headtr1ck
Copy link

Bug Report

mypy 0.981 and 0.982 consider Hashable and None to be overlapping.
I know that technically it is correct, since None is indeed hashable, but the way that None is used in python for default values makes this overlap inconvenient.

I could not find any hint in the changelog that indicates that this has changed.

To Reproduce

from typing import Hashable

@overload
def x(a: Hashable) -> Hashable: ...

@overload
def x(a: None = None) -> None: ...

def x(a: Hashable | None = None) -> Hashable | None:
    return a

Expected Behavior

Like mypy <= 0.971 no issue here.

Actual Behavior

error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]

Other

In case the new behavior is intended, is there a way to specify a "hashable but not None" type?

Your Environment

  • Mypy version used: 0.981 (and 0.982, 0.971 to compare)
  • Mypy command-line flags: /
  • Mypy configuration options from mypy.ini (and other config files): show_error_codes = True
  • Python version used: 3.9.7
@headtr1ck headtr1ck added the bug mypy got something wrong label Oct 3, 2022
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Oct 3, 2022

Side effect of #13303.

Like you say, these overloads do overlap, and in fact you likely want to switch the order of them (and then type ignore the overlap lint, mypy will still understand what's going on).

For more type system features, maybe follow python/typing#801. But Hashable is just a tricky type.

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2022
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