| 483 | return ck1._diff(ck2) |
| 484 | |
| 485 | def _whats_different(self, other: CacheKey) -> Iterator[str]: |
| 486 | k1 = self.key |
| 487 | k2 = other.key |
| 488 | |
| 489 | stack: List[int] = [] |
| 490 | pickup_index = 0 |
| 491 | while True: |
| 492 | s1, s2 = k1, k2 |
| 493 | for idx in stack: |
| 494 | s1 = s1[idx] |
| 495 | s2 = s2[idx] |
| 496 | |
| 497 | for idx, (e1, e2) in enumerate(zip_longest(s1, s2)): |
| 498 | if idx < pickup_index: |
| 499 | continue |
| 500 | if e1 != e2: |
| 501 | if isinstance(e1, tuple) and isinstance(e2, tuple): |
| 502 | stack.append(idx) |
| 503 | break |
| 504 | else: |
| 505 | yield "key%s[%d]: %s != %s" % ( |
| 506 | "".join("[%d]" % id_ for id_ in stack), |
| 507 | idx, |
| 508 | e1, |
| 509 | e2, |
| 510 | ) |
| 511 | else: |
| 512 | stack.pop(-1) |
| 513 | break |
| 514 | |
| 515 | def _diff(self, other: CacheKey) -> str: |
| 516 | return ", ".join(self._whats_different(other)) |