Closed
Description
Hello.
In Fedora, we are again trying to prepare the new Python 3.11 soon and during the rebuild of our packages, we have discovered that some tests of attrs package fail:
We are building attrs 21.4.0 together with Python 3.11.0~a3 (changelog)
=================================== 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 =======