[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-22 Thread Tzu-ping Chung
Change by Tzu-ping Chung : -- pull_requests: +29625 pull_request: https://github.com/python/cpython/pull/31495 ___ Python tracker ___

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-14 Thread Andrew Svetlov
Andrew Svetlov added the comment: >From my point of view, both sync and async functions can be cached. Sync and async iterators/generators are other beasts: they don't return a value but generate a series of items. The series can be long and memory-consuming, I doubt if it should be cached

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Note that there is a similar issue with cached generators. >>> from functools import * >>> @lru_cache() ... def g(): ... yield 1 ... >>> list(g()) [1] >>> list(g()) [] I am not sure that it is safe to detect awaitables and iterables in caching

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-14 Thread Andrew Svetlov
Andrew Svetlov added the comment: Agree. Let's start from async functions support by `functools.lru_cache`. If we will have an agreement that cached_property is an important use-case we can return to this issue. I have a feeling that async lru_cache is much more important.

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-14 Thread Tzu-ping Chung
Tzu-ping Chung added the comment: I agree that `print(await a.hello)` does look awkward, although I know some would disagree. (Context: I submitted this BPO after a colleague of mine at $WORK pointed out the behavioural difference between `functools` and `cached_property to me.) Personally

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-13 Thread Andrew Svetlov
Andrew Svetlov added the comment: I have a design question. Does `print(await a.hello)` look awkward? I'm not speaking about correction. In asyncio code I have seen before, `await val` means waiting for a future object. `await func()` means async function call. `await obj.attr` looks more

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-13 Thread Tzu-ping Chung
Change by Tzu-ping Chung : -- keywords: +patch pull_requests: +29476 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31314 ___ Python tracker ___

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Something like: _unset = ['unset'] class CachedAwaitable: def __init__(self, awaitable): self.awaitable = awaitable self.result = _unset def __await__(self): if self.result is _unset: self.result = yield from

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-10 Thread Andrew Svetlov
Andrew Svetlov added the comment: You can return a wrapper from __get__ that awaits the inner function and saves the result somewhere. -- ___ Python tracker ___

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-10 Thread Tzu-ping Chung
Tzu-ping Chung added the comment: > should not use asyncio directly but 'async def', 'await', and > `inspect.iscoroutine()` / `inspect.iscoroutinefunction()` instead. Hmm, this introduces some difficulties. Since a coroutine can only be awaited once, a new coroutine needs to be returned

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-09 Thread Andrew Svetlov
Andrew Svetlov added the comment: Pull Request is welcome! I would say that the PR should not use asyncio directly but 'async def', 'await', and `inspect.iscoroutine()` / `inspect.iscoroutinefunction()` instead. The property should work with any async framework, not asyncio only. --

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-09 Thread Alex Waygood
Change by Alex Waygood : -- nosy: +asvetlov, rhettinger, yselivanov ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-08 Thread Éric Araujo
Change by Éric Araujo : -- versions: -Python 3.10, Python 3.8, Python 3.9 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue46622] Support decorating a coroutine with functools.cached_property

2022-02-02 Thread Tzu-ping Chung
New submission from Tzu-ping Chung : 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: