When creating a subclass of an attr object, I would expect setting cmp=False to cause the subclass to be hashable. Right now it inherits the hash settings from its parent and ignores the cmp settings for hashing.
import attr
@attr.s
class Foo:
pass
@attr.s(cmp=False)
class Bar(Foo):
pass
assert Foo.__hash__ is None, "Foo incorrectly has a hash method"
## passes
assert Bar.__hash__ is object.__hash__, "Bar is missing the identity hash method"
## fails
The issue I believe is this elif block assumes that the class is inheriting from object and thereby getting its __hash__ method. Adding a line to explicitly add the __hash__ method would fix the problem.
The workaround I am using is just adding the __hash__ method after the class is defined, so
@attr.s(cmp=False)
class Bar(Foo):
pass
Bar.__hash__ = object.__hash__
When creating a subclass of an attr object, I would expect setting
cmp=Falseto cause the subclass to be hashable. Right now it inherits the hash settings from its parent and ignores the cmp settings for hashing.The issue I believe is this elif block assumes that the class is inheriting from
objectand thereby getting its__hash__method. Adding a line to explicitly add the__hash__method would fix the problem.The workaround I am using is just adding the
__hash__method after the class is defined, so