Skip to content

MyPy does not enforce Hashability #2455

Open
@rowillia

Description

@rowillia

For example, the following code is illegal in Python 3 (implementing __eq__ shadows your __hash__ implementation with None in Python 3)

class Foo(object):
  def __init__(self, x):
    self.x = x
  def __eq__(self, other):
    if not isinstance(other, Foo):
      return NotImplemented
    return self.x == other.x

set_of_foo = {Foo(1), Foo(2)}

Poking around the code, AFAICT mypy doesn't do any Hashable checks. I don't see any other Protocols being checked in checker.py. Is there any existing tickets around supporting Protocols in mypy?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions