MCPcopy Index your code
hub / github.com/python/cpython / HashKey

Class HashKey

Lib/test/test_context.py:593–623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

591
592
593class HashKey:
594 _crasher = None
595
596 def __init__(self, hash, name, *, error_on_eq_to=None):
597 assert hash != -1
598 self.name = name
599 self.hash = hash
600 self.error_on_eq_to = error_on_eq_to
601
602 def __repr__(self):
603 return f'<Key name:{self.name} hash:{self.hash}>'
604
605 def __hash__(self):
606 if self._crasher is not None and self._crasher.error_on_hash:
607 raise HashingError
608
609 return self.hash
610
611 def __eq__(self, other):
612 if not isinstance(other, HashKey):
613 return NotImplemented
614
615 if self._crasher is not None and self._crasher.error_on_eq:
616 raise EqError
617
618 if self.error_on_eq_to is not None and self.error_on_eq_to is other:
619 raise ValueError(f'cannot compare {self!r} to {other!r}')
620 if other.error_on_eq_to is not None and other.error_on_eq_to is self:
621 raise ValueError(f'cannot compare {other!r} to {self!r}')
622
623 return (self.name, self.hash) == (other.name, other.hash)
624
625
626class KeyStr(str):

Callers 15

test_hashkey_helper_1Method · 0.85
test_hamt_collision_1Method · 0.85
test_hamt_collision_3Method · 0.85
test_hamt_delete_1Method · 0.85
test_hamt_delete_2Method · 0.85
test_hamt_delete_3Method · 0.85
test_hamt_delete_4Method · 0.85
test_hamt_delete_5Method · 0.85
test_hamt_items_1Method · 0.85
test_hamt_items_2Method · 0.85
test_hamt_keys_1Method · 0.85
test_hamt_eq_1Method · 0.85

Calls

no outgoing calls

Tested by 15

test_hashkey_helper_1Method · 0.68
test_hamt_collision_1Method · 0.68
test_hamt_collision_3Method · 0.68
test_hamt_delete_1Method · 0.68
test_hamt_delete_2Method · 0.68
test_hamt_delete_3Method · 0.68
test_hamt_delete_4Method · 0.68
test_hamt_delete_5Method · 0.68
test_hamt_items_1Method · 0.68
test_hamt_items_2Method · 0.68
test_hamt_keys_1Method · 0.68
test_hamt_eq_1Method · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…