This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author uranusjr
Recipients uranusjr
Date 2022-02-03.07:28:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Currently, decorating a coroutine with cached_property would cache the coroutine itself. But this is not useful in any way since a coroutine cannot be awaited multiple times.

Running this code:

    import asyncio
    import functools

    class A:
        async def hello(self):
            return 'yo'

    async def main():
        a = A()
        print(await a.hello)
        print(await a.hello)


    Traceback (most recent call last):
      File "", line 15, in <module>
      File "/lib/python3.10/asyncio/", line 44, in run
        return loop.run_until_complete(main)
      File "/lib/python3.10/asyncio/", line 641, in run_until_complete
        return future.result()
      File "", line 12, in main
        print(await a.hello)
    RuntimeError: cannot reuse already awaited coroutine

The third-party cached_property package, on the other hand, detects a coroutine and caches its result instead. I feel this is a more useful behaviour.
Date User Action Args
2022-02-03 07:28:28uranusjrsetrecipients: + uranusjr
2022-02-03 07:28:28uranusjrsetmessageid: <>
2022-02-03 07:28:28uranusjrlinkissue46622 messages
2022-02-03 07:28:28uranusjrcreate