(self)
| 582 | self.assertNotEqual(C(3, 10), C(4, 10)) |
| 583 | |
| 584 | def test_no_unhashable_default(self): |
| 585 | # See bpo-44674. |
| 586 | class Unhashable: |
| 587 | __hash__ = None |
| 588 | |
| 589 | unhashable_re = 'mutable default .* for field a is not allowed' |
| 590 | with self.assertRaisesRegex(ValueError, unhashable_re): |
| 591 | @dataclass |
| 592 | class A: |
| 593 | a: dict = {} |
| 594 | |
| 595 | with self.assertRaisesRegex(ValueError, unhashable_re): |
| 596 | @dataclass |
| 597 | class A: |
| 598 | a: Any = Unhashable() |
| 599 | |
| 600 | # Make sure that the machinery looking for hashability is using the |
| 601 | # class's __hash__, not the instance's __hash__. |
| 602 | with self.assertRaisesRegex(ValueError, unhashable_re): |
| 603 | unhashable = Unhashable() |
| 604 | # This shouldn't make the variable hashable. |
| 605 | unhashable.__hash__ = lambda: 0 |
| 606 | @dataclass |
| 607 | class A: |
| 608 | a: Any = unhashable |
| 609 | |
| 610 | def test_hash_field_rules(self): |
| 611 | # Test all 6 cases of: |
nothing calls this directly
no test coverage detected