Skip to content

[BUG]: Python 3.14.0a3 test failure: test_roundtrip_with_dict: AttributeError: 'pybind11_tests.pickling.PickleableWithDict' object has no attribute 'dynamic' + test_dynamic_attributes #5499

Description

@befeleme

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.13.6

Problem description

I attempt to build pybind11 2.13.6 with Python 3.14.0a3 for Fedora Linux, the 3 tests have started to fail since a3.

What's new in Python 3.14 states:

Set the default protocol version on the pickle module to 5. For more details, see pickle protocols.

___________________________ test_dynamic_attributes ____________________________

    @pytest.mark.xfail("env.PYPY")
    def test_dynamic_attributes():
        instance = m.DynamicClass()
        assert not hasattr(instance, "foo")
        assert "foo" not in dir(instance)
    
        # Dynamically add attribute
        instance.foo = 42
        assert hasattr(instance, "foo")
        assert instance.foo == 42
        assert "foo" in dir(instance)
    
        # __dict__ should be accessible and replaceable
        assert "foo" in instance.__dict__
        instance.__dict__ = {"bar": True}
>       assert not hasattr(instance, "foo")
E       AssertionError: assert not True
E        +  where True = hasattr(<pybind11_tests.methods_and_attributes.DynamicClass object at 0x7f7c18238330>, 'foo')

instance   = <pybind11_tests.methods_and_attributes.DynamicClass object at 0x7f7c18238330>

../../tests/test_methods_and_attributes.py:312: AssertionError
----------------------------- Captured stdout call -----------------------------
### test_submodule_methods_and_attributes(module_&)::DynamicClass @ 0x5588e466d1b0 created via default constructor
_________________ test_roundtrip_with_dict[PickleableWithDict] _________________

cls_name = 'PickleableWithDict'

    @pytest.mark.xfail("env.PYPY")
    @pytest.mark.parametrize("cls_name", ["PickleableWithDict", "PickleableWithDictNew"])
    def test_roundtrip_with_dict(cls_name):
        cls = getattr(m, cls_name)
        p = cls("test_value")
        p.extra = 15
        p.dynamic = "Attribute"
    
        data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL)
        p2 = pickle.loads(data)
        assert p2.value == p.value
        assert p2.extra == p.extra
>       assert p2.dynamic == p.dynamic
E       AttributeError: 'pybind11_tests.pickling.PickleableWithDict' object has no attribute 'dynamic'

cls        = <class 'pybind11_tests.pickling.PickleableWithDict'>
cls_name   = 'PickleableWithDict'
data       = b'\x80\x05\x95`\x00\x00\x00\x00\x00\x00\x00\x8c\x17pybind11_tests.pickling\x94\x8c\x12PickleableWithDict\x94\x93\x94)\x81\x94\x8c\ntest_value\x94K\x0f}\x94\x8c\x07dynamic\x94\x8c\tAttribute\x94s\x87\x94b.'
p          = <pybind11_tests.pickling.PickleableWithDict object at 0x7f7c182395e0>
p2         = <pybind11_tests.pickling.PickleableWithDict object at 0x7f7c18239470>

../../tests/test_pickling.py:52: AttributeError
_______________ test_roundtrip_with_dict[PickleableWithDictNew] ________________

cls_name = 'PickleableWithDictNew'

    @pytest.mark.xfail("env.PYPY")
    @pytest.mark.parametrize("cls_name", ["PickleableWithDict", "PickleableWithDictNew"])
    def test_roundtrip_with_dict(cls_name):
        cls = getattr(m, cls_name)
        p = cls("test_value")
        p.extra = 15
        p.dynamic = "Attribute"
    
        data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL)
        p2 = pickle.loads(data)
        assert p2.value == p.value
        assert p2.extra == p.extra
>       assert p2.dynamic == p.dynamic
E       AttributeError: 'pybind11_tests.pickling.PickleableWithDictNew' object has no attribute 'dynamic'

cls        = <class 'pybind11_tests.pickling.PickleableWithDictNew'>
cls_name   = 'PickleableWithDictNew'
data       = b'\x80\x05\x95c\x00\x00\x00\x00\x00\x00\x00\x8c\x17pybind11_tests.pickling\x94\x8c\x15PickleableWithDictNew\x94\x93\x94)\x81\x94\x8c\ntest_value\x94K\x0f}\x94\x8c\x07dynamic\x94\x8c\tAttribute\x94s\x87\x94b.'
p          = <pybind11_tests.pickling.PickleableWithDictNew object at 0x7f7c18239750>
p2         = <pybind11_tests.pickling.PickleableWithDictNew object at 0x7f7c182398c0>

Reproducible example code


Is this a regression? Put the last known working version here if it is.

Not a regression

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions