Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: test_lazy_load raises RecursionError with Python 3.13.0a5 #26093

@befeleme

Description

@befeleme

Describe the issue:

I try to build numpy 1.26.4 in Fedora Linux with Python 3.13.0a5 containing the fix for @LIBPYTHON@ usage (python/cpython#116746). test_lazy_load unexpectedly raises Recursion Error.

Reproduce the code example:

none

Error message:

________________________________ test_lazy_load ________________________________

    @pytest.mark.filterwarnings("ignore:The NumPy module was reloaded")
    def test_lazy_load():
        # gh-22045. lazyload doesn't import submodule names into the namespace
        # muck with sys.modules to test the importing system
        old_numpy = sys.modules.pop("numpy")
    
        numpy_modules = {}
        for mod_name, mod in list(sys.modules.items()):
            if mod_name[:6] == "numpy.":
                numpy_modules[mod_name] = mod
                sys.modules.pop(mod_name)
    
        try:
            # create lazy load of numpy as np
            spec = find_spec("numpy")
            module = module_from_spec(spec)
            sys.modules["numpy"] = module
            loader = LazyLoader(spec.loader)
            loader.exec_module(module)
            np = module
    
            # test a subpackage import
>           from numpy.lib import recfunctions

loader     = <importlib.util.LazyLoader object at 0x7f07a3f64c80>
mod        = <module 'pydoc' from '/usr/lib64/python3.13/pydoc.py'>
mod_name   = 'pydoc'
module     = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
np         = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
numpy_modules = {'numpy.__config__': <module 'numpy.__config__' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/p...lddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/core/_dtype_ctypes.py'>, ...}
old_numpy  = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
spec       = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])

../../../../BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/tests/test_lazyloading.py:30: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
<frozen importlib._bootstrap>:1360: in _find_and_load
    ???
        import_    = <built-in function __import__>
        module     = <object object at 0x7f07ea940060>
        name       = 'numpy.lib'
<frozen importlib._bootstrap>:1316: in _find_and_load_unlocked
    ???
        import_    = <built-in function __import__>
        name       = 'numpy.lib'
        parent     = 'numpy'
        parent_module = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        parent_spec = None
        path       = None
<frozen importlib.util>:209: in __getattribute__
    ???
        __dict__   = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        __spec__   = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])
        attr       = '__path__'
        attrs_now  = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        attrs_then = {'__cached__': '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycach...packages/numpy/__init__.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, ...}
        attrs_updated = {}
        key        = '__cached__'
        loader_state = {'__class__': <class 'module'>, '__dict__': {'__cached__': '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/l...t 0x7f07a3e33c20>, ...}, 'is_loading': True, 'lock': <unlocked _thread.RLock object owner=0 count=0 at 0x7f07a3492740>}
        original_name = 'numpy'
        self       = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        value      = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycache__/__init__.cpython-313.pyc'
../../../../BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py:113: in <module>
    from . import version
        AxisError  = <class 'numpy.exceptions.AxisError'>
        ComplexWarning = <class 'numpy.exceptions.ComplexWarning'>
        ModuleDeprecationWarning = <class 'numpy.exceptions.ModuleDeprecationWarning'>
        TooHardError = <class 'numpy.exceptions.TooHardError'>
        VisibleDeprecationWarning = <class 'numpy.exceptions.VisibleDeprecationWarning'>
        _CopyMode  = <enum '_CopyMode'>
        _NoValue   = <no value>
        __builtins__ = <builtins>
        __cached__ = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycache__/__init__.cpython-313.pyc'
        __doc__    = '\nNumPy\n=====\n\nProvides\n  1. An array object of arbitrary homogeneous items\n  2. Fast mathematical operations ov...en\navailable as array methods, i.e. ``x = np.array([1,2,3]); x.sort()``.\nExceptions to this rule are documented.\n\n'
        __file__   = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'
        __loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>
        __name__   = 'numpy'
        __package__ = 'numpy'
        __path__   = ['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy']
        __spec__   = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])
        _globals   = <module 'numpy._globals' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/_globals.py'>
        _utils     = <module 'numpy._utils' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/_utils/__init__.py'>
        exceptions = <module 'numpy.exceptions' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/exceptions.py'>
        sys        = <module 'sys' (built-in)>
        warnings   = <module 'warnings' from '/usr/lib64/python3.13/warnings.py'>
<frozen importlib._bootstrap>:1412: in _handle_fromlist
    ???
        fromlist   = ('version',)
        import_    = <built-in function __import__>
        module     = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        recursive  = False
        x          = 'version'
<frozen importlib.util>:209: in __getattribute__
    ???
        __dict__   = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        __spec__   = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])
        attr       = 'version'
        attrs_now  = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        attrs_then = {'__cached__': '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycach...packages/numpy/__init__.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, ...}
        attrs_updated = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        key        = 'AxisError'
        loader_state = {'__class__': <class 'module'>, '__dict__': {'__cached__': '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/l...t 0x7f07a3e33c20>, ...}, 'is_loading': True, 'lock': <unlocked _thread.RLock object owner=0 count=0 at 0x7f07a3492740>}
        original_name = 'numpy'
        self       = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        value      = <class 'numpy.exceptions.AxisError'>
../../../../BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py:113: in <module>
    from . import version
        AxisError  = <class 'numpy.exceptions.AxisError'>
        ComplexWarning = <class 'numpy.exceptions.ComplexWarning'>
        ModuleDeprecationWarning = <class 'numpy.exceptions.ModuleDeprecationWarning'>
        TooHardError = <class 'numpy.exceptions.TooHardError'>
        VisibleDeprecationWarning = <class 'numpy.exceptions.VisibleDeprecationWarning'>
        _CopyMode  = <enum '_CopyMode'>
        _NoValue   = <no value>
        __builtins__ = <builtins>
        __cached__ = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycache__/__init__.cpython-313.pyc'
        __doc__    = '\nNumPy\n=====\n\nProvides\n  1. An array object of arbitrary homogeneous items\n  2. Fast mathematical operations ov...en\navailable as array methods, i.e. ``x = np.array([1,2,3]); x.sort()``.\nExceptions to this rule are documented.\n\n'
        __file__   = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'
        __loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>
        __name__   = 'numpy'
        __package__ = 'numpy'
        __path__   = ['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy']
        __spec__   = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])
        _globals   = <module 'numpy._globals' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/_globals.py'>
        _utils     = <module 'numpy._utils' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/_utils/__init__.py'>
        exceptions = <module 'numpy.exceptions' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/exceptions.py'>
        sys        = <module 'sys' (built-in)>
        warnings   = <module 'warnings' from '/usr/lib64/python3.13/warnings.py'>
<frozen importlib._bootstrap>:1412: in _handle_fromlist
    ???
E   RecursionError: maximum recursion depth exceeded
        fromlist   = ('version',)
        import_    = <built-in function __import__>
        module     = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        recursive  = False
        x          = 'version'
!!! Recursion detected (same locals & position)

Python and NumPy Versions:

Python 3.13.0a5, numpy 1.26.4 (from Fedora)

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions