| 378 | |
| 379 | |
| 380 | class 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 | |
| 413 | class KeyStr(str): |
no outgoing calls