Skip to content

tests/cloudpickle_test.py::CloudPickleTest::test_locally_defined_class_with_type_hints fails with Python 3.14.0b1 #567

@mgorny

Description

@mgorny

On top of c025de7:

$ tox -e py314
py314: install_deps> python -I -m pip install -r dev-requirements.txt
.pkg: install_requires> python -I -m pip install flit_core
.pkg: _optional_hooks> python /usr/lib/python3.13/site-packages/pyproject_api/_backend.py True flit_core.buildapi
.pkg: get_requires_for_build_sdist> python /usr/lib/python3.13/site-packages/pyproject_api/_backend.py True flit_core.buildapi
.pkg: get_requires_for_build_wheel> python /usr/lib/python3.13/site-packages/pyproject_api/_backend.py True flit_core.buildapi
.pkg: prepare_metadata_for_build_wheel> python /usr/lib/python3.13/site-packages/pyproject_api/_backend.py True flit_core.buildapi
.pkg: build_sdist> python /usr/lib/python3.13/site-packages/pyproject_api/_backend.py True flit_core.buildapi
py314: install_package> python -I -m pip install --force-reinstall --no-deps /tmp/anyio/cloudpickle/.tox/.tmp/package/1/cloudpickle-3.2.0.dev0.tar.gz
py314: commands[0]> pytest -lv --maxfail=5
========================================================= test session starts =========================================================
platform linux -- Python 3.14.0b1, pytest-8.3.5, pluggy-1.5.0 -- /tmp/anyio/cloudpickle/.tox/py314/bin/python
cachedir: .tox/py314/.pytest_cache
rootdir: /tmp/anyio/cloudpickle
configfile: tox.ini
plugins: cov-6.1.1
collected 272 items                                                                                                                   

[…]
============================================================== FAILURES ===============================================================
_____________________________________ CloudPickleTest.test_locally_defined_class_with_type_hints ______________________________________

self = <tests.cloudpickle_test.CloudPickleTest testMethod=test_locally_defined_class_with_type_hints>

    def test_locally_defined_class_with_type_hints(self):
        with subprocess_worker(protocol=self.protocol) as worker:
            for type_ in _all_types_to_test():
    
                class MyClass:
                    def method(self, arg: type_) -> type_:
                        return arg
    
                MyClass.__annotations__ = {"attribute": type_}
    
                def check_annotations(obj, expected_type, expected_type_str):
                    assert obj.__annotations__["attribute"] == expected_type
                    assert obj.method.__annotations__["arg"] == expected_type
                    assert obj.method.__annotations__["return"] == expected_type
                    return "ok"
    
                obj = MyClass()
>               assert check_annotations(obj, type_, "type_") == "ok"

MyClass    = <class 'tests.cloudpickle_test.CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.MyClass'>
check_annotations = <function CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.check_annotations at 0x7f11d88b1bc0>
obj        = <tests.cloudpickle_test.CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.MyClass object at 0x7f11d8811010>
self       = <tests.cloudpickle_test.CloudPickleTest testMethod=test_locally_defined_class_with_type_hints>
type_      = <class 'tests.cloudpickle_test._all_types_to_test.<locals>.C'>
worker     = <tests.testutils._Worker object at 0x7f11d9076f10>

tests/cloudpickle_test.py:2667: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

obj = <tests.cloudpickle_test.CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.MyClass object at 0x7f11d8811010>
expected_type = <class 'tests.cloudpickle_test._all_types_to_test.<locals>.C'>, expected_type_str = 'type_'

    def check_annotations(obj, expected_type, expected_type_str):
>       assert obj.__annotations__["attribute"] == expected_type
E       AttributeError: 'MyClass' object has no attribute '__annotations__'. Did you mean: '__annotations_cache__'?

expected_type = <class 'tests.cloudpickle_test._all_types_to_test.<locals>.C'>
expected_type_str = 'type_'
obj        = <tests.cloudpickle_test.CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.MyClass object at 0x7f11d8811010>

tests/cloudpickle_test.py:2661: AttributeError
_________________________________ Protocol2CloudPickleTest.test_locally_defined_class_with_type_hints _________________________________

self = <tests.cloudpickle_test.Protocol2CloudPickleTest testMethod=test_locally_defined_class_with_type_hints>

    def test_locally_defined_class_with_type_hints(self):
        with subprocess_worker(protocol=self.protocol) as worker:
            for type_ in _all_types_to_test():
    
                class MyClass:
                    def method(self, arg: type_) -> type_:
                        return arg
    
                MyClass.__annotations__ = {"attribute": type_}
    
                def check_annotations(obj, expected_type, expected_type_str):
                    assert obj.__annotations__["attribute"] == expected_type
                    assert obj.method.__annotations__["arg"] == expected_type
                    assert obj.method.__annotations__["return"] == expected_type
                    return "ok"
    
                obj = MyClass()
>               assert check_annotations(obj, type_, "type_") == "ok"

MyClass    = <class 'tests.cloudpickle_test.CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.MyClass'>
check_annotations = <function CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.check_annotations at 0x7f11d6f47530>
obj        = <tests.cloudpickle_test.CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.MyClass object at 0x7f11d7222cf0>
self       = <tests.cloudpickle_test.Protocol2CloudPickleTest testMethod=test_locally_defined_class_with_type_hints>
type_      = <class 'tests.cloudpickle_test._all_types_to_test.<locals>.C'>
worker     = <tests.testutils._Worker object at 0x7f11d6f46a40>

tests/cloudpickle_test.py:2667: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

obj = <tests.cloudpickle_test.CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.MyClass object at 0x7f11d7222cf0>
expected_type = <class 'tests.cloudpickle_test._all_types_to_test.<locals>.C'>, expected_type_str = 'type_'

    def check_annotations(obj, expected_type, expected_type_str):
>       assert obj.__annotations__["attribute"] == expected_type
E       AttributeError: 'MyClass' object has no attribute '__annotations__'. Did you mean: '__annotations_cache__'?

expected_type = <class 'tests.cloudpickle_test._all_types_to_test.<locals>.C'>
expected_type_str = 'type_'
obj        = <tests.cloudpickle_test.CloudPickleTest.test_locally_defined_class_with_type_hints.<locals>.MyClass object at 0x7f11d7222cf0>

tests/cloudpickle_test.py:2661: AttributeError
========================================================== warnings summary ===========================================================
tests/cloudpickle_test.py::CloudPickleTest::test_tornado_coroutine
  /tmp/anyio/cloudpickle/.tox/py314/lib/python3.14/site-packages/tornado/platform/asyncio.py:389: DeprecationWarning: 'asyncio.DefaultEventLoopPolicy' is deprecated and slated for removal in Python 3.16
    _BasePolicy = asyncio.DefaultEventLoopPolicy

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================= short test summary info =======================================================
FAILED tests/cloudpickle_test.py::CloudPickleTest::test_locally_defined_class_with_type_hints - AttributeError: 'MyClass' object has no attribute '__annotations__'. Did you mean: '__annotations_cache__'?
FAILED tests/cloudpickle_test.py::Protocol2CloudPickleTest::test_locally_defined_class_with_type_hints - AttributeError: 'MyClass' object has no attribute '__annotations__'. Did you mean: '__annotations_cache__'?
================================== 2 failed, 253 passed, 15 skipped, 2 xfailed, 1 warning in 18.38s ===================================
py314: exit 1 (18.71 seconds) /tmp/anyio/cloudpickle> pytest -lv --maxfail=5 pid=411471
.pkg: _exit> python /usr/lib/python3.13/site-packages/pyproject_api/_backend.py True flit_core.buildapi
  py314: FAIL code 1 (31.15=setup[12.43]+cmd[18.71] seconds)
  evaluation failed :( (31.23 seconds)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions