-
Notifications
You must be signed in to change notification settings - Fork 1
Add ska_helpers.utils module with LazyDict #16
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
This smells like collections.defaultdict. In what way is it different? |
ah, never mind. I see the difference. |
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 like the idea of lazy-initialized variables.
I am not a fan of the get()
syntax. Where do you intend to use LazyVal?
To some extent, this functionality can be provided by module attributes, providing a module's __getattr__
method (https://www.python.org/dev/peps/pep-0562/). Why would you prefer this?
I note that the documentation is not yet finished:
- LazyVal is not documented
- no code examples
- ska theme is not used
I assume you are doing this, hence your comments in slack today.
self._loaded = True | ||
|
||
# Delete these so pickling always works (pickling a func can fail) | ||
del self._load_func |
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 thought maybe there were some pickle-specific methods you could define in the class (short of a custom Pickler) that would be more general, but this is readable.
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 guess I was thinking of __getstate__
.
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.
The current method would help with other serializations like YAML as well.
@javierggt - I'm also not a fan of the My first thought for this task was also the module level If you can find a way to make this work then that would be great, though there are some other issues with I used LazyVal here: |
@javierggt @jeanconn - I think I have addressed all the review comments. |
Description
This adds a new module
ska_helpers.utils
as a generic drop box for Ska utilities that don't have a better home.The first entry is the
LazyDict
class, which currently appears separately in Ska.engarchive and maude. This version is more complete/robust and somewhat tested.This PR also converts the docstrings to numpydoc format.
Testing