Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

implementation for "unhashable" is wrong #192

Closed
wbolster opened this issue Mar 24, 2016 · 1 comment
Closed

implementation for "unhashable" is wrong #192

wbolster opened this issue Mar 24, 2016 · 1 comment

Comments

@wbolster
Copy link
Contributor

The implementation to make a class unhashable which has been added in #184 is wrong. See commit daa213d for the changes.

The python data model docs at
https://docs.python.org/3/reference/datamodel.html#object.__hash__ state:

A class that overrides __eq__() and does not define __hash__() will have its __hash__() implicitly set to None. When the __hash__() method of a class is None, instances of the class will raise an appropriate TypeError when a program attempts to retrieve their hash value, and will also be correctly identified as unhashable when checking isinstance(obj, collections.Hashable).

Instead of raising a TypeError from __hash__(), the method should not be present at all, and a __hash__ = None should be in its place, like this:

class SomeClass(...):
    __hash__ = None

    def __eq__(self, other):
        ...
wbolster referenced this issue Mar 24, 2016
mutable container should be unhashable
@lxyu
Copy link
Contributor

lxyu commented Mar 24, 2016

should be resolved in 9e5a863

@lxyu lxyu closed this as completed Mar 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants