-
Notifications
You must be signed in to change notification settings - Fork 118
Description
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 an int 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:
box = MyBox({"a": {"b": {"c": 5}}})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 or box_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!