Bug 2039259 - python-attrs fails to build with Python 3.11: TypeError: super(type, obj): obj must be an instance or subtype of type
Summary: python-attrs fails to build with Python 3.11: TypeError: super(type, obj): ob...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python-attrs
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Lumír Balhar
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.11 F37FTBFS
TreeView+ depends on / blocked
 
Reported: 2022-01-11 11:31 UTC by Tomáš Hrnčiar
Modified: 2023-06-20 02:22 UTC (History)
7 users (show)

Fixed In Version: python-attrs-21.4.0-5.fc37
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-06-24 11:14:18 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Tomáš Hrnčiar 2022-01-11 11:31:03 UTC
python-attrs fails to build with Python 3.11.0a3.


=================================== FAILURES ===================================
_______________________ test_init_subclass_vanilla[True] _______________________

slots = True

    @pytest.mark.parametrize("slots", [True, False])
    def test_init_subclass_vanilla(slots):
        """
        `super().__init_subclass__` can be used if the subclass is not an attrs
        class both with dict and slotted classes.
        """
    
        @attr.s(slots=slots)
        class Base:
            def __init_subclass__(cls, param, **kw):
                super().__init_subclass__(**kw)
                cls.param = param
    
>       class Vanilla(Base, param="foo"):

tests/test_init_subclass.py:27: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'tests.test_init_subclass.test_init_subclass_vanilla.<locals>.Vanilla'>
param = 'foo', kw = {}

    def __init_subclass__(cls, param, **kw):
>       super().__init_subclass__(**kw)
E       TypeError: super(type, obj): obj must be an instance or subtype of type

tests/test_init_subclass.py:24: TypeError
_____________ TestClosureCellRewriting.test_closure_cell_rewriting _____________

self = <tests.test_slots.TestClosureCellRewriting object at 0x7fb02ec6da50>

    def test_closure_cell_rewriting(self):
        """
        Slotted classes support proper closure cell rewriting.
    
        This affects features like `__class__` and the no-arg super().
        """
        non_slot_instance = C1(x=1, y="test")
        slot_instance = C1Slots(x=1, y="test")
    
        assert non_slot_instance.my_class() is C1
>       assert slot_instance.my_class() is C1Slots
E       AssertionError: assert <class 'tests.test_slots.C1Slots'> is C1Slots
E        +  where <class 'tests.test_slots.C1Slots'> = <bound method C1Slots.my_class of C1Slots(x=1, y='test')>()
E        +    where <bound method C1Slots.my_class of C1Slots(x=1, y='test')> = C1Slots(x=1, y='test').my_class

tests/test_slots.py:424: AssertionError
__________________ TestClosureCellRewriting.test_inheritance ___________________

self = <tests.test_slots.TestClosureCellRewriting object at 0x7fb02ec658d0>

    def test_inheritance(self):
        """
        Slotted classes support proper closure cell rewriting when inheriting.
    
        This affects features like `__class__` and the no-arg super().
        """
    
        @attr.s
        class C2(C1):
            def my_subclass(self):
                return __class__
    
        @attr.s
        class C2Slots(C1Slots):
            def my_subclass(self):
                return __class__
    
        non_slot_instance = C2(x=1, y="test")
        slot_instance = C2Slots(x=1, y="test")
    
        assert non_slot_instance.my_class() is C1
>       assert slot_instance.my_class() is C1Slots
E       AssertionError: assert <class 'tests.test_slots.C1Slots'> is C1Slots
E        +  where <class 'tests.test_slots.C1Slots'> = <bound method C1Slots.my_class of C2Slots(x=1, y='test')>()
E        +    where <bound method C1Slots.my_class of C2Slots(x=1, y='test')> = C2Slots(x=1, y='test').my_class

tests/test_slots.py:451: AssertionError
________________ TestClosureCellRewriting.test_cls_static[True] ________________

self = <tests.test_slots.TestClosureCellRewriting object at 0x7fb02ec71c90>
slots = True

    @pytest.mark.parametrize("slots", [True, False])
    def test_cls_static(self, slots):
        """
        Slotted classes support proper closure cell rewriting for class- and
        static methods.
        """
        # Python can reuse closure cells, so we create new classes just for
        # this test.
    
        @attr.s(slots=slots)
        class C:
            @classmethod
            def clsmethod(cls):
                return __class__
    
>       assert C.clsmethod() is C
    
        @attr.s(slots=slots)
E       AssertionError: assert <class 'tests.test_slots.TestClosureCellRewriting.test_cls_static.<locals>.C'> is <class 'tests.test_slots.TestClosureCellRewriting.test_cls_static.<locals>.C'>
E        +  where <class 'tests.test_slots.TestClosureCellRewriting.test_cls_static.<locals>.C'> = <bound method TestClosureCellRewriting.test_cls_static.<locals>.C.clsmethod of <class 'tests.test_slots.TestClosureCellRewriting.test_cls_static.<locals>.C'>>()
E        +    where <bound method TestClosureCellRewriting.test_cls_static.<locals>.C.clsmethod of <class 'tests.test_slots.TestClosureCellRewriting.test_cls_static.<locals>.C'>> = <class 'tests.test_slots.TestClosureCellRewriting.test_cls_static.<locals>.C'>.clsmethod

tests/test_slots.py:475: AssertionError
____________________ test_slots_super_property_get_shurtcut ____________________

    @pytest.mark.skipif(PY2, reason="shortcut super() is PY3-only.")
    def test_slots_super_property_get_shurtcut():
        """
        On Python 3, the `super()` shortcut is allowed.
        """
    
        @attr.s(slots=True)
        class A(object):
            x = attr.ib()
    
            @property
            def f(self):
                return self.x
    
        @attr.s(slots=True)
        class B(A):
            @property
            def f(self):
                return super().f ** 2
    
>       assert B(11).f == 121

tests/test_slots.py:739: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = B(x=11)

    @property
    def f(self):
>       return super().f ** 2
E       TypeError: super(type, obj): obj must be an instance or subtype of type

tests/test_slots.py:737: TypeError
=============================== warnings summary ===============================
../../BUILDROOT/python-attrs-21.4.0-1.fc36.x86_64/usr/lib/python3.11/site-packages/attr/_make.py:918
tests/test_init_subclass.py::test_init_subclass_vanilla[True]
tests/test_slots.py::TestClosureCellRewriting::test_cls_static[True]
tests/test_slots.py::test_slots_empty_cell
tests/test_slots.py::test_slots_super_property_get
tests/test_slots.py::test_slots_super_property_get_shurtcut
  /builddir/build/BUILDROOT/python-attrs-21.4.0-1.fc36.x86_64/usr/lib/python3.11/site-packages/attr/_make.py:918: RuntimeWarning: Running interpreter doesn't sufficiently support code object introspection.  Some features like bare super() or accessing __class__ will not work with slotted classes.
    set_closure_cell(cell, cls)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================== short test summary info ============================
SKIPPED [1] tests/test_3rd_party.py:14: could not import 'cloudpickle': No module named 'cloudpickle'
SKIPPED [1] tests/test_make.py:469: No old-style classes in Py3
SKIPPED [1] tests/test_make.py:1002: PY2-specific keyword-only error behavior
SKIPPED [1] tests/test_make.py:1967: Needs to be only caught on Python 2.
SKIPPED [1] tests/test_make.py:2333: Pre-3.10 only.
SKIPPED [1] tests/test_pyright.py:26: Requires pyright.
SKIPPED [1] tests/test_slots.py:485: can't break CodeType.replace() via monkeypatch
SKIPPED [1] tests/test_slots.py:532: slots without weakref_slot should only work on PyPy
XFAIL tests/test_setattr.py::TestSetAttr::test_slotted_confused
FAILED tests/test_init_subclass.py::test_init_subclass_vanilla[True] - TypeEr...
FAILED tests/test_slots.py::TestClosureCellRewriting::test_closure_cell_rewriting
FAILED tests/test_slots.py::TestClosureCellRewriting::test_inheritance - Asse...
FAILED tests/test_slots.py::TestClosureCellRewriting::test_cls_static[True]
FAILED tests/test_slots.py::test_slots_super_property_get_shurtcut - TypeErro...
====== 5 failed, 1166 passed, 8 skipped, 1 xfailed, 6 warnings in 19.65s =======

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

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.11/fedora-rawhide-x86_64/03141508-python-attrs/

For all our attempts to build python-attrs with Python 3.11, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/package/python-attrs/

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.11:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/

Let us know here if you have any questions.

Python 3.11 is planned to be included in Fedora 37. To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.11.
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 Lumír Balhar 2022-01-14 06:43:00 UTC
Reported upstream: https://github.com/python-attrs/attrs/issues/907

Comment 2 Lumír Balhar 2022-01-17 06:24:09 UTC
Upstream reported the issue to BPO and it's interesting to read: https://bugs.python.org/issue46404

Comment 3 Miro Hrončok 2022-01-18 10:58:18 UTC
A workaround: https://github.com/python-attrs/attrs/pull/910

Comment 4 Lumír Balhar 2022-01-21 08:35:56 UTC
The workaround is currently applied in the Python 3.11 COPR and tests are enabled there so we won't miss any possible new incompatibility and we can wait for the final fix.

Comment 5 Ben Cotton 2022-02-08 21:09:09 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle.
Changing version to 36.

Comment 6 Miro Hrončok 2022-06-22 11:53:38 UTC
Ben, does this problem really block other packages? attrs were built without tests first.

Comment 7 Ben Beasley 2022-06-22 12:47:45 UTC
(In reply to Miro Hrončok from comment #6)
> Ben, does this problem really block other packages? attrs were built without
> tests first.

As noted in [1], and as I realized after linking the bug, maybe not. I can unblock bug 2099099 until python-jsonpickle is fixed and I can verify whether python-sarif-om has any attrs-related issues or not.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2099099#c4

Comment 8 Fedora Update System 2022-06-24 11:11:10 UTC
FEDORA-2022-cc940fb919 has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2022-cc940fb919

Comment 9 Fedora Update System 2022-06-24 11:14:18 UTC
FEDORA-2022-cc940fb919 has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.