Commit 8c3377b
committed
Fix mangled __slots__ attribute lost for subclass instances
`_dict_from_slots` unmangled each slot name using the concrete instance
type (`type(object).__name__`). A mangled slot such as `__id` is stored under
the name of the class that *declared* it (e.g. `_Parent__id`), so for a
subclass instance the lookup used the wrong name (`_Child__id`), `hasattr`
returned False, and the parent-defined slot was silently dropped.
Pair each slot with the class in the MRO that declared it and unmangle using
that class's name.
Closes #5061 parent c59636c commit 8c3377b
3 files changed
Lines changed: 29 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
506 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
507 | 510 | | |
508 | 511 | | |
509 | | - | |
| 512 | + | |
510 | 513 | | |
511 | 514 | | |
512 | 515 | | |
| |||
522 | 525 | | |
523 | 526 | | |
524 | 527 | | |
525 | | - | |
| 528 | + | |
526 | 529 | | |
527 | | - | |
| 530 | + | |
528 | 531 | | |
529 | | - | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
530 | 537 | | |
531 | 538 | | |
532 | 539 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
823 | 823 | | |
824 | 824 | | |
825 | 825 | | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
826 | 842 | | |
827 | 843 | | |
828 | 844 | | |
| |||
0 commit comments