Bug 2254528

Summary: python-astroid fails to build with Python 3.13: 2 tests fail
Product: [Fedora] Fedora Reporter: Karolina Surma <ksurma>
Component: python-astroidAssignee: Gwyn Ciesla <gwync>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: gwync, ksurma, mhroncok, orion
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-astroid-3.2.3-1.fc40 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-07-25 01:28:21 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: 2244836    

Description Karolina Surma 2023-12-14 11:47:42 UTC
python-astroid fails to build with Python 3.13.0a2.

=================================== FAILURES ===================================
___________ test_dataclasses_subscript_inference_recursion_error_39 ____________

    @pytest.mark.skipif(
        not PY39_PLUS,
        reason="Exact inference with dataclasses (replace function) in python3.9",
    )
    def test_dataclasses_subscript_inference_recursion_error_39():
        code = """
        from dataclasses import dataclass, replace
    
        @dataclass
        class ProxyConfig:
            auth: str = "/auth"
    
    
        a = ProxyConfig("")
        test_dict = {"proxy" : {"auth" : "", "bla" : "f"}}
    
        foo = test_dict['proxy']
        replace(a, **test_dict['proxy']) # This fails
        """
        node = extract_node(code)
        infer_val = util.safe_infer(node)
>       assert isinstance(infer_val, Instance)
E       assert False
E        +  where False = isinstance(Uninferable, Instance)

tests/test_inference.py:6731: AssertionError
_______________ TypingBrain.test_typing_annotated_subscriptable ________________

self = <tests.brain.test_brain.TypingBrain testMethod=test_typing_annotated_subscriptable>

    @test_utils.require_version(minver="3.9")
    def test_typing_annotated_subscriptable(self):
        """Test typing.Annotated is subscriptable with __class_getitem__"""
        node = builder.extract_node(
            """
        import typing
        typing.Annotated[str, "data"]
        """
        )
        inferred = next(node.infer())
        assert isinstance(inferred, nodes.ClassDef)
>       assert isinstance(inferred.getattr("__class_getitem__")[0], nodes.FunctionDef)

tests/brain/test_brain.py:641: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ClassDef.Annotated l.10 at 0x7faefc93e120>, name = '__class_getitem__'
context = None, class_context = True

    def getattr(
        self,
        name: str,
        context: InferenceContext | None = None,
        class_context: bool = True,
    ) -> list[InferenceResult]:
        """Get an attribute from this class, using Python's attribute semantic.
    
        This method doesn't look in the :attr:`instance_attrs` dictionary
        since it is done by an :class:`Instance` proxy at inference time.
        It may return an :class:`Uninferable` object if
        the attribute has not been
        found, but a ``__getattr__`` or ``__getattribute__`` method is defined.
        If ``class_context`` is given, then it is considered that the
        attribute is accessed from a class context,
        e.g. ClassDef.attribute, otherwise it might have been accessed
        from an instance as well. If ``class_context`` is used in that
        case, then a lookup in the implicit metaclass and the explicit
        metaclass will be done.
    
        :param name: The attribute to look for.
    
        :param class_context: Whether the attribute can be accessed statically.
    
        :returns: The attribute.
    
        :raises AttributeInferenceError: If the attribute cannot be inferred.
        """
        if not name:
            raise AttributeInferenceError(target=self, attribute=name, context=context)
    
        # don't modify the list in self.locals!
        values: list[InferenceResult] = list(self.locals.get(name, []))
        for classnode in self.ancestors(recurs=True, context=context):
            values += classnode.locals.get(name, [])
    
        if name in self.special_attributes and class_context and not values:
            result = [self.special_attributes.lookup(name)]
            if name == "__bases__":
                # Need special treatment, since they are mutable
                # and we need to return all the values.
                result += values
            return result
    
        if class_context:
            values += self._metaclass_lookup_attribute(name, context)
    
        # Remove AnnAssigns without value, which are not attributes in the purest sense.
        for value in values.copy():
            if isinstance(value, node_classes.AssignName):
                stmt = value.statement()
                if isinstance(stmt, node_classes.AnnAssign) and stmt.value is None:
                    values.pop(values.index(value))
    
        if not values:
>           raise AttributeInferenceError(target=self, attribute=name, context=context)
E           astroid.exceptions.AttributeInferenceError: '__class_getitem__' not found on <ClassDef.Annotated l.10 at 0x7faefc93e120>.

astroid/nodes/scoped_nodes/scoped_nodes.py:2425: AttributeInferenceError
=========================== short test summary info ============================
FAILED tests/test_inference.py::test_dataclasses_subscript_inference_recursion_error_39
FAILED tests/brain/test_brain.py::TypingBrain::test_typing_annotated_subscriptable
=========== 2 failed, 1581 passed, 77 skipped, 16 xfailed in 18.03s ============

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

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

For all our attempts to build python-astroid with Python 3.13, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/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.13:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/

Let us know here if you have any questions.

Python 3.13 is planned to be included in Fedora 41.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.13.
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.

Comment 1 Aoife Moloney 2024-02-15 23:07:49 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 40 development cycle.
Changing version to 40.

Comment 2 Karolina Surma 2024-03-27 12:44:44 UTC
Two more tests fail with Python 3.13.0a5:

FAILED tests/brain/test_pathlib.py::test_inference_parents - AssertionError: ...
FAILED tests/brain/test_pathlib.py::test_inference_parents_subscript_index - ...

Comment 3 Miro HronĨok 2024-06-02 22:10:05 UTC
https://src.fedoraproject.org/rpms/python-astroid/pull-request/8 deselects the failing tests to unblock the rebuild.

Comment 4 Fedora Update System 2024-07-16 14:59:46 UTC
FEDORA-2024-a77be3252e (python-astroid-3.2.3-1.fc40) has been submitted as an update to Fedora 40.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-a77be3252e

Comment 5 Fedora Update System 2024-07-17 08:21:25 UTC
FEDORA-2024-a77be3252e has been pushed to the Fedora 40 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2024-a77be3252e`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2024-a77be3252e

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 6 Fedora Update System 2024-07-25 01:28:21 UTC
FEDORA-2024-a77be3252e (python-astroid-3.2.3-1.fc40) has been pushed to the Fedora 40 stable repository.
If problem still persists, please make note of it in this bug report.