-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add a @cached_property implementation #6149
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
Conversation
location[2], | ||
) # type: Tuple[str, Optional[int], str] | ||
return self._location | ||
location = self.reportinfo() |
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.
With regard to this I've noticed that we'd want to cache reportinfo()
probably/maybe - any ideas how to do this? Should/could we wrap it in a property with a different name then? lru
might also be an option, but seems bad with just a single item?!
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.
I think for methods we can implement a simple decorator that does something similar to cached_property
, say cached_method
. It should be even simpler than cached_property
.
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.
lru might also be an option, but seems bad with just a single item?!
lru_cache is very fast in my experience (in Python terms...). However, it can't really be used on methods, it leaks self
.
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.
lets leave the method caching for later for now,
it can trivially be implemented as shim for a new private property if necessary
This is a useful utility to abstract the caching property idiom. It is in compat.py since eventually it will be replaced by functools.cached_property. Fixes pytest-dev#6131.
31c8d55
to
42a46ea
Compare
Squashed and rebased -- will merge once it passes CI. |
Hmm, is adding a |
@bluetech |
Did you mean "not ignore" -> "ignore"? In any case, I can't merge because it says "Required statuses must pass before merging". So I'll try to sort it out later. |
I've meant to not put "# pragma" comments there to ignore it with the report. |
I've removed the requirement on/for that check. /cc @nicoddemus |
This is a useful utility to abstract the caching property idiom.
It is in compat.py since eventually it will be replaced by
functools.cached_property.
Fixes #6131.