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 serhiy.storchaka
Recipients asvetlov, rhettinger, serhiy.storchaka, uranusjr, yselivanov
Date 2022-02-23.16:39:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645634383.03.0.813789420751.issue46622@roundup.psfhosted.org>
In-reply-to
Content
I think that it would be simpler to add a decorator which wraps the result of an asynchronous function into an object which can be awaited more than once:

def reawaitable(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        return CachedAwaitable(func(*args, **kwargs))
    return wrapper

It can be combined with lru_cache and cached_property any third-party caching decorator. No access to internals of the cache is needed.

@lru_cache()
@reawaitable
async def coro(...):
    ...

@cached_property
@reawaitable
async def prop(self):
    ...
History
Date User Action Args
2022-02-23 16:39:43serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, asvetlov, yselivanov, uranusjr
2022-02-23 16:39:43serhiy.storchakasetmessageid: <1645634383.03.0.813789420751.issue46622@roundup.psfhosted.org>
2022-02-23 16:39:43serhiy.storchakalinkissue46622 messages
2022-02-23 16:39:42serhiy.storchakacreate