MCPcopy Index your code
hub / github.com/RustPython/RustPython / HashKey

Class HashKey

Lib/test/test_context.py:380–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

378
379
380class HashKey:
381 _crasher = None
382
383 def __init__(self, hash, name, *, error_on_eq_to=None):
384 assert hash != -1
385 self.name = name
386 self.hash = hash
387 self.error_on_eq_to = error_on_eq_to
388
389 def __repr__(self):
390 return f'<Key name:{self.name} hash:{self.hash}>'
391
392 def __hash__(self):
393 if self._crasher is not None and self._crasher.error_on_hash:
394 raise HashingError
395
396 return self.hash
397
398 def __eq__(self, other):
399 if not isinstance(other, HashKey):
400 return NotImplemented
401
402 if self._crasher is not None and self._crasher.error_on_eq:
403 raise EqError
404
405 if self.error_on_eq_to is not None and self.error_on_eq_to is other:
406 raise ValueError(f'cannot compare {self!r} to {other!r}')
407 if other.error_on_eq_to is not None and other.error_on_eq_to is self:
408 raise ValueError(f'cannot compare {other!r} to {self!r}')
409
410 return (self.name, self.hash) == (other.name, other.hash)
411
412
413class 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