Closed taldcroft closed 3 years ago
This smells like collections.defaultdict.
In what way is it different?
ah, never mind. I see the difference.
@javierggt - I'm also not a fan of the .get()
syntax, but I don't see a way around it.
My first thought for this task was also the module level __getattr__
and indeed I was excited to use this new feature. However, __getattr__
only works for attribute access from outside the module itself. So my_module.lazy_attribute
works, but within my_module
trying to access lazy_attribute
just gives a NameError.
If you can find a way to make this work then that would be great, though there are some other issues with __getattr__
in this context. The main is that in any module that wants to use lazy values then a __getattr__
function needs to be defined by the user module to use those lazy values. It isn't obvious there is a nice way to handle this, especially if the user module is independently defining __getattr__
for another reason.
I used LazyVal here: https://github.com/sot/chandra_aca/pull/108/files#diff-21392387835d093a39ee20461a8c92f248b70ac2a69150f23ffbf4c7a7f15860R29
@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