| 591 | |
| 592 | |
| 593 | class 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 | |
| 626 | class KeyStr(str): |
no outgoing calls
searching dependent graphs…