-
Notifications
You must be signed in to change notification settings - Fork 107
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
Support for tracking the box "namespace" #226
Comments
Actually, I have a similar problem, though formulated a bit differently. I use Box heavily with So I have sub-classed Box (to First, I re-implemented b = Box()
b['z.y.z'] = "Hi"
# b == {'x': {'y': {'z': 1}}} Such initializations are possible: b = TBox({
'x.y.z': 1,
'x.y.w': 2,
'x.m': 100,
'x.n': {'k.p':200}
}) In general, I believe working with dots should be symmetrical for reading and writing. Implementation is rather straightforward and does not seem to conflict with the rest of Box functionality: class TBox(Box):
...
def __setitem__(self, key, value):
if '.' in key:
node, tail = key.split('.', 1)
if node not in self:
super().__setitem__(node, {})
self[node].__setitem__(tail, value)
else:
super().__setitem__(key, value) What do you think about making that default behavior in I am also missing But before some solution for the default_box problem is found, |
+1 for this feature. |
Adding this feature in Box 7! Please test and give feedback if possible |
7.0.0rc0 nicely replaced my workarounds, fixing a couple bugs! Though, I did have some issues with some of the wheels. |
* Adding #169 default functions with the box_instance and key parameter (thanks to Коптев Роман Викторович) * Adding #170 Be able to initialize with a flattened dict - by using DDBox (thanks to Ash A.) * Adding #192 box_dots treats all keys with periods in them as separate keys (thanks to Rexbard) * Adding #211 support for properties and setters in subclasses (thanks to Serge Lu and David Aronchick) * Adding #226 namespace to track changes to the box (thanks to Jacob Hayes) * Adding #236 iPython detection to prevent adding attribute lookup words (thanks to Nishikant Parmar) * Adding #238 allow ``|`` and ``+`` for frozen boxes (thanks to Peter B) * Adding new DDBox class (Default Dots Box) that is a subclass of SBox * Fixing #235 how ``|`` and ``+`` updates were performed for right operations (thanks to aviveh21) * Fixing #234 typos (thanks to Martin Schorfmann) * Fixing no implicit optionals with type hinting
Added in 7.0.0 |
I have some nested Boxes using an overridden
__convert_and_store
in a subclass to convert values to an expected type (eg: I want all values to be anint
or some other custom class). For that conversion, I would like to know the "namespace" of the Box/value in order to reference it in the conversion and show nicer error messages.For example, when handling the conversion of
5
in the example below:I would like to know that I'm assigning to
("a", "b", "c")
.This is quite hard to setup only in a subclass because of the recursive value conversion (and copying) during
__init__
and conversion doesn't give a good hook to intercept after the box is created, but before sub-boxes are created.I think the easiest way to support this is by adding a
box_path
orbox_namespace
param to__init__
(defaulting to()
) and then into_box_config
, which can be passed through (and extended) in__get_default
and__convert_and_store
when creating sub-boxes.Is this something you'd be open to? I'd be happy to make a PR for this if so!
The text was updated successfully, but these errors were encountered: