Repository navigation
Commit 623bef9
authored
[mypyc] Fix undeclared module in C when base class is a re-export (#22357)
Fixes mypyc/mypyc#1163. Fixes mypyc/mypyc#1155. Fixes mypyc/mypyc#1033.
If a non-native class (for example, an enum) had a base class that was
imported through a re-export, the generated C failed to compile:
```python
from backports.strenum import StrEnum # Defined in backports.strenum.strenum
class C(StrEnum): # error: 'CPyModule_backports___strenum___strenum' undeclared
x = "x"
```
The base class was loaded from the module where it's defined, but that
module wasn't explicitly imported. Subclassing `ctypes.Structure`
(defined in `_ctypes`) had the same issue. Now base classes from other
modules are loaded using `get_module_attr`, which imports the module if
needed.
This also fixes two related issues with non-native classes. If the
defining module was imported only in a function body that hadn't run
yet, the base was looked up from None. A nested class used as a base
(such as `Outer.Inner`) generated an undeclared module reference for
`Outer`, since the module name was derived from the fullname.1 parent f0eb638 commit 623bef9
2 files changed
Lines changed: 86 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
667 | 667 | | |
668 | 668 | | |
669 | 669 | | |
670 | | - | |
671 | | - | |
672 | | - | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
673 | 674 | | |
674 | | - | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
675 | 681 | | |
676 | 682 | | |
677 | 683 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1593 | 1593 | | |
1594 | 1594 | | |
1595 | 1595 | | |
1596 | | - | |
1597 | | - | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
1598 | 1600 | | |
1599 | 1601 | | |
1600 | 1602 | | |
| 1603 | + | |
| 1604 | + | |
1601 | 1605 | | |
1602 | 1606 | | |
1603 | 1607 | | |
| |||
1724 | 1728 | | |
1725 | 1729 | | |
1726 | 1730 | | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
1727 | 1774 | | |
1728 | 1775 | | |
1729 | 1776 | | |
| |||
1748 | 1795 | | |
1749 | 1796 | | |
1750 | 1797 | | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
1751 | 1825 | | |
1752 | 1826 | | |
1753 | 1827 | | |
| |||
0 commit comments