Commit dbb53d9
committed
Fix of SF bug #475877 (Mutable subtype instances are hashable).
Rather than tweaking the inheritance of type object slots (which turns
out to be too messy to try), this fix adds a __hash__ to the list and
dict types (the only mutable types I'm aware of) that explicitly
raises an error. This has the advantage that list.__hash__([]) also
raises an error (previously, this would invoke object.__hash__([]),
returning the argument's address); ditto for dict.__hash__.
The disadvantage for this fix is that 3rd party mutable types aren't
automatically fixed. This should be added to the rules for creating
subclassable extension types: if you don't want your object to be
hashable, add a tp_hash function that raises an exception.
Also, it's possible that I've forgotten about other mutable types for
which this should be done.1 parent cb33165 commit dbb53d9
3 files changed
Lines changed: 41 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2571 | 2571 | | |
2572 | 2572 | | |
2573 | 2573 | | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
2574 | 2597 | | |
2575 | 2598 | | |
2576 | 2599 | | |
| |||
2623 | 2646 | | |
2624 | 2647 | | |
2625 | 2648 | | |
| 2649 | + | |
2626 | 2650 | | |
2627 | 2651 | | |
2628 | 2652 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1797 | 1797 | | |
1798 | 1798 | | |
1799 | 1799 | | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
1800 | 1807 | | |
1801 | 1808 | | |
1802 | 1809 | | |
| |||
1827 | 1834 | | |
1828 | 1835 | | |
1829 | 1836 | | |
1830 | | - | |
| 1837 | + | |
1831 | 1838 | | |
1832 | 1839 | | |
1833 | 1840 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1617 | 1617 | | |
1618 | 1618 | | |
1619 | 1619 | | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
1620 | 1627 | | |
1621 | 1628 | | |
1622 | 1629 | | |
| |||
1681 | 1688 | | |
1682 | 1689 | | |
1683 | 1690 | | |
1684 | | - | |
| 1691 | + | |
1685 | 1692 | | |
1686 | 1693 | | |
1687 | 1694 | | |
| |||
1771 | 1778 | | |
1772 | 1779 | | |
1773 | 1780 | | |
1774 | | - | |
| 1781 | + | |
1775 | 1782 | | |
1776 | 1783 | | |
1777 | 1784 | | |
| |||
0 commit comments