acoustid / mbdata

MusicBrainz SQLAlchemy Models
MIT License
97 stars 23 forks source link

Add __hash__ to PartialDate #53

Closed amCap1712 closed 1 year ago

amCap1712 commented 2 years ago

In Python 3, the data model was changed to not provide a __hash__ method if __eq__ is overriden in a class. PartialDate defines __eq__ but not __hash__ and is thus unhashable. To quote the docs,

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.abc.Hashable).

(from https://docs.python.org/3.7/reference/datamodel.html#object.__hash__)

We store PartialDate's in a set in SIR so it would be nice to make it hashable.

amCap1712 commented 2 years ago

Includes changes from #52 but not necessarily dependent on it.