-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync cached_property getter access #150
Sync cached_property getter access #150
Conversation
fa39a6b
to
7bac360
Compare
The CodeQL "Statement has no effect" reports for ellipsis all are false positives and can be ignored: github/codeql#11351 |
Thanks for this nice work! I need some time to review it, but at a glance I don't see any glaring problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. That is some nicely thought out code, I had to go back a few times when realising I misunderstood an edge case that you considered.
Aside from some minor things, there's three main points that I stumbled on:
- I don't think the fast path in
_await_impl
is worth the code size cost. Please correct me if I'm missing a reason to keep it. - The locked section in
_await_impl
could drop the lock more aggressively. - I'm not happy with either variant of the new parameter name. Unless you have an idea for a better one, I prefer to not expose it by making the parameter positional-only.
f60d000
to
73b981b
Compare
This should be ready for re-review now. |
Add an option to pass in a lock to the cached_property decorator, so the accessor is run just once even when multiple tasks are concurrently trying to await on the value.
73b981b
to
d2e442f
Compare
The static check failures are unrelated and will be fixed by #152, no need to duplicate them here. |
Add an option to pass in a lock to the
cached_property
decorator, so theaccessor is run just once even when multiple tasks are concurrently trying to
await on the value.
This PR fixes concurrent access to the property getter. Notable changes include:
cached_property
decorator now accepts either a getter coroutine method,or an async context manager. In the latter case a new decorator is returned
to accept the actual getter.
cached_property
internals with the stdlib.functools.cached_property version. Most notably, the test forinstance.__dict__
has been moved to__get__
, and the__wrapped__
and_name
attributes now match the attribtues on a stdlib cached property descriptor.Closes #149