Skip to content

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

Closed as not planned
@headtr1ck

Description

@headtr1ck

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

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