Closed
Description
@cdce8p already bisected this upstream to python/cpython#118532
To Reproduce
# Set up using something like:
# python3.13 -m pip install setuptools
# python3.13 -m pip install -e .
printf '
from non_native import pure_python_const
class CanRemoveThisClass:
pass
' > native.py
printf '
import native # circular import
pure_python_const = 10
' > non_native.py
rm -rf build
rm *.so
python3.13 -m mypyc native.py
python3.13 -c 'import native'
Using a debug build of Python, you get:
Assertion failed: (value == NULL), function _extensions_cache_set, file import.c, line 1325.
zsh: abort python3.13 -c 'import native
Using a non-debug build, you get:
Traceback (most recent call last):
File "<string>", line 1, in <module>
import native
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 921, in _load_unlocked
File "<frozen importlib._bootstrap>", line 819, in module_from_spec
File "<frozen importlib._bootstrap>", line 782, in _init_module_attrs
SystemError: extension module 'native' is already cached
mypyc transpiles Python code to an extension module that uses the C API. In the above, we compile native.py into an extension module and form an import cycle with a normal pure Python module
The C code mypyc generates is visible in the build directory