| 501 | def test_setdefault_atomic(self): |
| 502 | # Issue #13521: setdefault() calls __hash__ and __eq__ only once. |
| 503 | class Hashed(object): |
| 504 | def __init__(self): |
| 505 | self.hash_count = 0 |
| 506 | self.eq_count = 0 |
| 507 | def __hash__(self): |
| 508 | self.hash_count += 1 |
| 509 | return 42 |
| 510 | def __eq__(self, other): |
| 511 | self.eq_count += 1 |
| 512 | return id(self) == id(other) |
| 513 | hashed1 = Hashed() |
| 514 | y = {hashed1: 5} |
| 515 | hashed2 = Hashed() |
no outgoing calls
searching dependent graphs…