-
Notifications
You must be signed in to change notification settings - Fork 99
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
Auto attributes creation #9
Comments
I'm personally leaning towards doing keyword arguments, as that would allow for other customization and expansions in the future. I am mulling over how best to name them (so they aren't close to anything someone might have in a dictionary). Either something like Closing #5 as it was less detailed |
Sounds like separation of creating Box variants from using them would be valuable (separate namespaces with no awkward avoidance of overlap). So how about this: @box.closable
@box.autoattr
class MyClosableAutoBox(Box):
"""Customized ``Box``.""" Chances are you want to use such a beast at several places anyway, and then you'd have to curry the Box construction with those keyword args. 😬 Alas, Python3 only, but you could call the decorators explicitly in Python2. |
It's own namespace would be nice and simple, but for #6 need to have some sort of namespace pollution anyways, so I have been working on a way to make it near invisible. https://github.com/cdgriffith/Box/blob/auto_attr/box.py#L269 my_box = Box({"I call Hax!": "totally"}, default_box=True, conversion_box=True)
my_box.i_call_hax
# Out[8]: 'totally'
my_box.sub_box.another_box.boxes_the_whole_way_down = 'Yet another box'
my_box
# Out[10]: <Box: {'I call Hax!': 'totally', 'sub_box': {'another_box': {'boxes_the_whole_way_down': 'Yet another box'}}}> Could still make it into it's own subclass if those same options will always be repeated (still mulling over just adding a few of these as well for simplicity): class DefaultBox(Box):
def __init__(self, *args, **kwargs):
super(Box, self).__init__(*args, **kwargs)
self._box_config['default'] = True Thoughts? |
added |
IMHO this should work, possibly via a subtype (
AutoBox
) or__init__
keyword arg (auto_attr=True
).Another variant would be
OpenBox
combined with aclose()
method – i.e. allow path construction initially, but then switch to default mode (AttributeError
) after construction.The text was updated successfully, but these errors were encountered: