-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add word cache reset function #152
Conversation
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.
@eliotwrobson Overall looks good, but left you a few comments with some requested changes (mostly the name of the method itself).
Regarding preserving the API, I believe the @functools.lru_cache() decorator is the stdlib way to cache the output of methods. The only thing to note is that the method returns the cached output based on the arguments you pass to the function at call time. So foo(first='Eliot')
and foo(last='Robson')
will each be cache misses on the first call. But I think this is the behavior we want in most cases, anyway.
@caleb531 sounds good! As you pointed out, I made a mistake in the docs with the name in the first place 😅 so changing it is no problem. Regarding caching, using lru cache here is actually a mistake: https://youtu.be/sVjtp6tGo0g The use here would be for caching something like However, this changes the method into a property (so it is accessed by the client code differently). This might be more natural since users may expect cached properties to behave this way, but I also don't know if changing the API this way is the right move. |
@eliotwrobson Ah yes, I forgot that
The package doesn't seem like much overhead, but given how small this decorator is, we could just as easily include the implementation directly in the code. I could go either way. So this whole post of mine obviously implies that I'd still prefer members like Methods can have additional arguments in a way that's effectively future-proof with keyword arguments; properties can't no matter what you do. And as for the semantic argument: I tend to use properties to represent nouns/things, but when I have some check or operation to perform, I use a method. I recognize that Okay, thank you for coming to my TED talk. Please let me know your thoughts! |
I tend to agree, having these be methods allows more flexibility and conveys these are something to be computed. In the interest of writing less code, I'm inclined to go with the adding the optional dependency. So I will do that along with the renames described. |
@eliotwrobson Just want to say please feel free to continue to make changes, and just convert this PR out of Draft mode when it's ready for my re-review. |
@caleb531 looking over the changes I think this is ready to go! Flipping to open. |
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.
@eliotwrobson LGTM! 👍
Actually, one quick afterthought: How will all this additional caching behave if a user enables mutable automata? I guess they can just clear the caches manually as they make changes, correct? |
@caleb531 yes, they can manually clear cached methods by emptying the |
See title, adds a word cache reset function and precomputes the digraph used by the DFA. Resolves #148
In looking at this, I thought about using a cached property for some of the methods that return fixed information about the given DFAs. However, switching these to cached properties (with the decorator) requires using a slightly different API. @caleb531 what are your thoughts about changing this? Is there a way to provide this caching without changing the API? It would be great if there were a way to do this cleanly.