Implementing __eq__ without also implementing __hash__
168 return hashlib.blake2b(value.encode('utf-8'), digest_size=20).digest()
169
170
171class ShortLinkToBigIntComparator(Comparator): # pylint: disable=abstract-method172 """
173 Comparator to allow lookup by shortlink name instead of numeric id.
174
Implementing __eq__ without also implementing __hash__
623_MC = TypeVar('_MC', bound='MarkdownCompositeBase')
624
625
626class MarkdownCompositeBase(MutableComposite):627 """Represents Markdown text and rendered HTML as a composite column."""
628
629 config: ClassVar[MarkdownConfig]
Implementing __eq__ without also implementing __hash__
124 NOT_PRIVATE = {AUTO, PUBLIC}
125
126
127class ZBase32Comparator(Comparator[str]): # pylint: disable=abstract-method 128 """Comparator to allow lookup by Account.uuid_zbase32."""
129
130 def __eq__(self, other: object) -> sa.ColumnElement[bool]: # type: ignore[override]
Description
In order to conform to the object model, classes that define their own equality method should also define their own hash method, or be unhashable. If the hash method is not defined then the hash of the super class is used. This is unlikely to result in the expected behavior.
A class can be made unhashable by setting its __hash__
attribute to None.
In Python 3, if you define a class-level equality method and omit a __hash__
method then the class is automatically marked as unhashable.
It is recommended to implement a __hash__
method or set __hash__ = None
, whenever you define an __eq__
method for a class.