Bug 2026777 - python-cached_property fails to build with Python 3.11: AttributeError: module 'asyncio' has no attribute 'coroutine'
Summary: python-cached_property fails to build with Python 3.11: AttributeError: modul...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: python-cached_property
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Pete Travis
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.11
TreeView+ depends on / blocked
 
Reported: 2021-11-25 19:18 UTC by Tomáš Hrnčiar
Modified: 2021-12-08 14:09 UTC (History)
5 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2021-12-02 20:40:23 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github pydanny cached-property pull 267 0 None open Python 3.11 support: Don't use asyncio.coroutine if it's not available 2021-12-02 10:53:35 UTC

Description Tomáš Hrnčiar 2021-11-25 19:18:51 UTC
python-cached_property fails to build with Python 3.11.0a2.


==================================== ERRORS ====================================
___________ ERROR collecting tests/test_coroutine_cached_property.py ___________
tests/test_coroutine_cached_property.py:50: in <module>
    class TestCachedProperty(unittest.TestCase):
tests/test_coroutine_cached_property.py:55: in TestCachedProperty
    @asyncio.coroutine
E   AttributeError: module 'asyncio' has no attribute 'coroutine'
=========================== short test summary info ============================
ERROR tests/test_coroutine_cached_property.py - AttributeError: module 'async...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.11s ===============================

The @asyncio.coroutine decorator enabling legacy generator-based coroutines to be compatible with async/await code. The function has been deprecated since Python 3.8 and the removal was initially scheduled for Python 3.10. Use async def instead. (Contributed by Illia Volochii in bpo-43216.)

https://bugs.python.org/issue43216
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/02986843-python-cached_property/

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

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 Adam Williamson (Red Hat non-Fedora) 2021-11-25 20:54:48 UTC
I'm afraid I'm going to have to cry uncle on this one. I am no expert at all on async stuff, and cached_property is actually doing something kind of unusual with it which the release notes do not cover. It looks like it was all written before PEP 492 was a thing, and never updated. Its async test code uses this wrapper:

def unittest_run_loop(f):
    def wrapper(*args, **kwargs):
        coro = asyncio.coroutine(f)
        future = coro(*args, **kwargs)
        loop = asyncio.get_event_loop()
        loop.run_until_complete(future)

    return wrapper

which calls `asyncio.coroutine` *directly*. Then various tests (which are themselves decorated as `asyncio.coroutine`) have that wrapper applied to them. I sort of see the intent, I think - it means "just run this whole asynchronous test function until everything is exhausted" - but I don't really see how you'd translate that to the modern 'async def' syntax. Can anyone who's better at this stuff help?

I tried a couple of things - replacing the wrapper with just a call to `await(f(*args, **kwargs))`, and replacing the wrapper entirely with use of `@pytest.mark.asyncio` from pytest-asyncio - but those don't seem to work properly. With them, the tests pass, but I get warnings indicating the tests were never really run:

tests/test_async_cached_property.py::TestCachedProperty::test_cached_property
tests/test_coroutine_cached_property.py::TestCachedProperty::test_cached_property
  /usr/lib64/python3.10/unittest/case.py:549: RuntimeWarning: coroutine 'TestCachedProperty.test_cached_property' was never awaited
    method()

...and indeed, if I hack up a test such that it should fail (assert a wrong value), it doesn't.

Upstream on this project is very unresponsive lately, so I'm not sure I'll get anywhere filing an issue there, but I'll do it.

Comment 2 Petr Viktorin (pviktori) 2021-12-02 10:53:35 UTC
I've sent a PR upstream, you might want to take the patch: https://github.com/pydanny/cached-property/pull/267
With this, adding errors to the functions makes the tests fail.

cached_property is also available in the Python 3.8+ standard library (without asyncio integration though): https://docs.python.org/3/library/functools.html#functools.cached_property
It might be good to help projects that need cached_property start migrating to that.

Comment 3 Adam Williamson (Red Hat non-Fedora) 2021-12-02 19:35:03 UTC
Thanks, on both counts! I look after python-cached_property primarily because my own thing (fedfind) uses it. I can look at migrating to the functools one (I don't use asyncio stuff); the only issue may be maintaining support for EPEL 8, I'll have to look into that.

Comment 4 Adam Williamson (Red Hat non-Fedora) 2021-12-02 20:40:23 UTC
OK, successful Rawhide build with Petr's patch: https://koji.fedoraproject.org/koji/taskinfo?taskID=79522426 . Closing.

Comment 5 Petr Viktorin (pviktori) 2021-12-03 09:49:10 UTC
> the only issue may be maintaining support for EPEL 8, I'll have to look into that.

usually done with something like:

try:
    from functools import cached_property
except ImportError:
    # Python 3.7 and lower
    from cached_property import cached_property

and for conditional dependencies in Python metadata, see e.g. https://github.com/PyCQA/astroid/blob/6691a9e97373b28e15a76b747f78c041f2064df4/setup.cfg#L43

Comment 6 Adam Williamson (Red Hat non-Fedora) 2021-12-03 18:05:56 UTC
that's what I'm trying to avoid, because I hate having to maintain that kinda stuff :( and I don't know if the Fedora macros that handle tox dependencies know about / correctly handle that syntax (probably not, so I'd have to have conditionals in the spec file or fork it, and that again is the kinda stuff I don't want to deal with...)

What I'm saying is it'd be much easier if we could just package for Python 3.8 on EL 8, hint hint :P

Comment 7 Miro Hrončok 2021-12-03 18:31:11 UTC
> I don't know if the Fedora macros that handle tox dependencies know about / correctly handle that syntax

They do.

Comment 8 Adam Williamson (Red Hat non-Fedora) 2021-12-03 18:43:11 UTC
oh, that would help. Thanks.

Comment 9 Adam Williamson (Red Hat non-Fedora) 2021-12-07 21:57:32 UTC
unfortunately, looks like the pyproject-rpm-macros stuff doesn't exist in EPEL 8, and probably can't as EL 8's rpm is too old. So I can make the spec very shiny and simple for Fedora, but not for EPEL branches.

Comment 10 Miro Hrončok 2021-12-08 14:09:50 UTC
Indeed, that is the case.

However, at least the runtime dependency generator should work on EPEL 8.


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