Commit 7c5a1c4
committed
fix(mypyc): preserve inherited class attribute defaults under separate=True
Under separate=True, find_attr_initializers walked the full MRO and pulled
default-value AssignmentStmt nodes out of info.defn.defs.body. After mypy
loads a base class from its incremental cache, that body is always empty
(ClassDef.serialize deliberately doesn't serialize defs). When the
subclass got recompiled but the parent stayed cache-loaded, the
subclass's emitted __mypyc_defaults_setup silently dropped every
inherited initialization. Any access to an inherited attribute through
compiled code then raised "AttributeError: attribute X of <base>
undefined".
This fix changes the strategy under separate=True only: each class's
__mypyc_defaults_setup now sets just that class's own defaults, then
calls the nearest ancestor's __mypyc_defaults_setup to fold in inherited
ones (same shape as Python's __init__ chain). The chain is robust to
cache-loaded bases because it doesn't need their AST -- only that the
ancestor has a method_decl entry for __mypyc_defaults_setup, which the
cached ClassIR retains.
Without separate=True the original inline-everything path is preserved
as an optimization (the AST is always in memory, so the MRO walk is
safe and the chain call would be needless runtime overhead).
Added testIncrementalCrossModuleInheritedAttrDefaultsWithOverride to
run-multimodule.test which exercises the fix end-to-end under both
TestRunSeparate and TestRunMultiFile. It fails on master and passes
with the fix.1 parent e346010 commit 7c5a1c4
2 files changed
Lines changed: 101 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
745 | 746 | | |
746 | 747 | | |
747 | 748 | | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
748 | 763 | | |
749 | 764 | | |
750 | 765 | | |
| |||
758 | 773 | | |
759 | 774 | | |
760 | 775 | | |
761 | | - | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
762 | 782 | | |
763 | 783 | | |
764 | 784 | | |
| |||
800 | 820 | | |
801 | 821 | | |
802 | 822 | | |
803 | | - | |
804 | | - | |
805 | | - | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
806 | 832 | | |
807 | 833 | | |
808 | 834 | | |
809 | 835 | | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
810 | 846 | | |
811 | 847 | | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
812 | 856 | | |
813 | 857 | | |
814 | 858 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1680 | 1680 | | |
1681 | 1681 | | |
1682 | 1682 | | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
0 commit comments