Skip to content
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

Proposal: inheritance structure and annotate/validate behaviour #30

Open
RonnyPfannschmidt opened this issue Feb 15, 2016 · 2 comments
Open

Comments

@RonnyPfannschmidt
Copy link

while trying to implement a cached property variant that implements a annotate/validate behavior

i noticed that 2 implementation details could be shared in mixins

  • all thread support is implemented via adding a lock property and using it in __set__
  • ttl is using the current time as "annotation" and uses timedelta > ttl as validation

this would allow for a interesting hierarchy ill propose at the end

the annotate/validate behavior can be considered as a generalization of the ttl model
where ttl is just the annotation/validation based on time/ttl,
while annotate/validate could also do more extended checks like validating database connections
or doing inexpensive cache/db queries for values that where very expensive to query for

Hierachy

  • CachedProperty implementing the base behaviour
  • _ThreadSafeMixin implementign only the thread lock
  • ThreadSafeCachedPropery inheriting fromCachedProperty,_ThreadSafeMixin`
  • _AnnotatedCachedproperty implementing annotation/validation behaviour
    • annotation must result in a single object which is stored alongside the actual object
    • validation will receive only the annotation object, and must return a truth value
    • annotation may return the actual object in order to allow validation to use it
  • CachedPropertyWithTTL inheriting from _AnnotatedCachedproperty implementing ttl annotation/validation
  • AnnotatedCachedProperty. inheriting from _AnnotatedCachedproperty implementing exposure of the annotate/validate api
  • the thread-safe variants would just mix in the _ThreadSafeMixin again

since this is a larger structural change, i wanted to discuss before taking a stake at completely implementing it

on a sidenote - i already tried the thread safety unification,
but sharing the code for pessimistic retrieval from __dict__ caused the threading test for the normal cached property to fail

i suspect the gil is involved and i stepped back to discuss the idea at that point since debugging/verifying the gil involvement would eat way too much time right now

@pydanny pydanny changed the title Proppsal: inheritance structure and annotate/validate behaviour Proposal: inheritance structure and annotate/validate behaviour Sep 30, 2018
@pydanny
Copy link
Owner

pydanny commented Sep 30, 2018

Simply reviewing pull requests for this kind of 2.0 effort is going to be a major effort, comprising more free time than I have to spare. So as much as I think this is an interesting idea, we're going to have to defer it for the time being. 😞

@RonnyPfannschmidt
Copy link
Author

so far it hasnt come up in my work anymore as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants