Bug 2480142

Summary: python-astroid fails to build with Python 3.15: KeyError: "local variable ''sitedir'' is not defined"
Product: [Fedora] Fedora Reporter: Karolina Surma <ksurma>
Component: python-astroidAssignee: Gwyn Ciesla <gwync>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: gwync, ksurma, mhroncok, orion, thrnciar
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2026-05-20 19:01:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2412434    

Description Karolina Surma 2026-05-20 11:49:22 UTC
python-astroid fails to build with Python 3.15.0b1.

_______________ AstroidManagerTest.test_nested_namespace_import ________________

self = <tests.test_manager.AstroidManagerTest testMethod=test_nested_namespace_import>

    @pytest.mark.skipif(
        IS_PYPY,
        reason="PyPy provides no way to tell apart frozen stdlib from old-style namespace packages",
    )
    def test_nested_namespace_import(self) -> None:
        pth = "foogle_fax-0.12.5-py2.7-nspkg.pth"
        site.addpackage(resources.RESOURCE_PATH, pth, [])
        try:
>           self.manager.ast_from_module_name("foogle.crank")

tests/test_manager.py:219: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astroid/manager.py:273: in ast_from_module_name
    raise e
astroid/manager.py:218: in ast_from_module_name
    found_spec = self.file_from_module_name(modname, context_file)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <astroid.manager.AstroidManager object at 0x7fca93a9e8d0>
modname = 'foogle.crank', contextfile = None

    def file_from_module_name(
        self, modname: str, contextfile: str | None
    ) -> spec.ModuleSpec:
        try:
            value = self._mod_file_cache[(modname, contextfile)]
        except KeyError:
            try:
                value = file_info_from_modpath(
                    modname.split("."), context_file=contextfile
                )
            except ImportError as e:
                value = AstroidImportError(
                    "Failed to import module {modname} with error:\n{error}.",
                    modname=modname,
                    # we remove the traceback here to save on memory usage (since these exceptions are cached)
                    error=e.with_traceback(None),
                )
            self._mod_file_cache[(modname, contextfile)] = value
        if isinstance(value, AstroidBuildingError):
            # we remove the traceback here to save on memory usage (since these exceptions are cached)
>           raise value.with_traceback(None)  # pylint: disable=no-member
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E           astroid.exceptions.AstroidImportError: Failed to import module foogle.crank with error:
E           No module named foogle.crank.

astroid/manager.py:321: AstroidImportError

During handling of the above exception, another exception occurred:

self = <tests.test_manager.AstroidManagerTest testMethod=test_nested_namespace_import>

    @pytest.mark.skipif(
        IS_PYPY,
        reason="PyPy provides no way to tell apart frozen stdlib from old-style namespace packages",
    )
    def test_nested_namespace_import(self) -> None:
        pth = "foogle_fax-0.12.5-py2.7-nspkg.pth"
        site.addpackage(resources.RESOURCE_PATH, pth, [])
        try:
            self.manager.ast_from_module_name("foogle.crank")
        finally:
>           sys.modules.pop("foogle")
E           KeyError: 'foogle'

tests/test_manager.py:221: KeyError
----------------------------- Captured stderr call -----------------------------
Error in import line from /builddir/build/BUILD/python-astroid-4.1.2-build/astroid-4.1.2/tests/testdata/python3/data/foogle_fax-0.12.5-py2.7-nspkg.pth: import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('foogle',));ie = os.path.exists(os.path.join(p,'__init__.py'));m = not ie and sys.modules.setdefault('foogle', types.ModuleType('foogle'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
  Traceback (most recent call last):
    File "<frozen site>", line 319, in _exec_imports
    File "<string>", line 1, in <module>
  KeyError: "local variable ''sitedir'' is not defined"
Error in import line from /builddir/build/BUILD/python-astroid-4.1.2-build/astroid-4.1.2/tests/testdata/python3/data/foogle_fax-0.12.5-py2.7-nspkg.pth: import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('foogle','crank'));ie = os.path.exists(os.path.join(p,'__init__.py'));m = not ie and sys.modules.setdefault('foogle.crank', types.ModuleType('foogle.crank'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
  Traceback (most recent call last):
    File "<frozen site>", line 319, in _exec_imports
    File "<string>", line 1, in <module>
  KeyError: "local variable ''sitedir'' is not defined"
=========================== short test summary info ============================
FAILED tests/brain/test_dataclasses.py::test_kw_only_sentinel - AssertionErro...
FAILED tests/test_manager.py::AstroidManagerTest::test_namespace_and_file_mismatch
FAILED tests/test_manager.py::AstroidManagerTest::test_namespace_package_pth_support
FAILED tests/test_manager.py::AstroidManagerTest::test_nested_namespace_import
= 4 failed, 1926 passed, 80 skipped, 15 xfailed, 35 subtests passed in 24.65s ==

https://docs.python.org/3.15/whatsnew/3.15.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.15-b1/fedora-rawhide-x86_64/10487831-python-astroid/

For all our attempts to build python-astroid with Python 3.15, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.15-b1/package/python-astroid/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.15:
https://copr.fedorainfracloud.org/coprs/g/python/python3.15-b1/

Let us know here if you have any questions.

Python 3.15 is planned to be included in Fedora 45.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.15.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.