This document is for Kombu's development version, which can be significantly different from previous releases. Get the stable docs here: 5.0.

Source code for kombu.utils.collections

"""Custom maps, sequences, etc."""


[docs]class HashedSeq(list): """Hashed Sequence. Type used for hash() to make sure the hash is not generated multiple times. """ __slots__ = 'hashvalue' def __init__(self, *seq): self[:] = seq self.hashvalue = hash(seq) def __hash__(self): return self.hashvalue
[docs]def eqhash(o): """Call ``obj.__eqhash__``.""" try: return o.__eqhash__() except AttributeError: return hash(o)
[docs]class EqualityDict(dict): """Dict using the eq operator for keying.""" def __getitem__(self, key): h = eqhash(key) if h not in self: return self.__missing__(key) return super().__getitem__(h) def __setitem__(self, key, value): return super().__setitem__(eqhash(key), value) def __delitem__(self, key): return super().__delitem__(eqhash(key))