You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use treedict more and more to distribute parameters of scientific simulations. However, I regularly get bitten by implicit branch creation. I misspell the name of a branch I want to retrieve, and rather than raising an exception, it gives me a dandling branch, which creates problems when the value is actually used, which can be in some completely different place in the code. Hard to debug.
Moreover, since dandling branches are invisible, I can't even check that dandling branches exist or were accessed, which makes any kind of automatic error-checking on that aspect (eg. unit test) impossible.
Would it be possible to disable the implicit branch creation, without freezing the structure ? For instance, something like :
t = treedict.TreeDict()
t.disable_implicit()
t.b = 3 # creating node is ok
t.a.b.c = 1 # creating branch implicitly with non dandling leaves is ok
t.b # accessing existing node is ok
t.a # accessing existing branch is ok
t.c # raise Error.
I looked at the code, but did not find the right combination of flag to make this work.
The text was updated successfully, but these errors were encountered:
I apologize -- I just saw this comment. I've started a new job in the last year, and only recently got back to maintaining my open source projects. Did you figure out the answer?
It should be possible to disable implicit branch creation by calling t.freeze(structure_only = True). This allows existing values to be altered, but no new branches to be created.
is a problem. Because python would have to create or access a and b before figuring out what I want to do with it. So having both things happen is not possible.
t.freeze(structure_only = True does not solve my problem. I want to add things to the tree, and I can't unfreeze the tree.
I ended up cooking up my own solution (pure python), that adds optional typechecks and logging capabilities to the mix, and has an option strict when you can't create a branch or leaf you didn't declare. Not very pythonic (I also exclusively use methods prefixed by underscore), but I can verify that things happened as they should after an experiment finishes. You can have a look at it here. It was largely inspired by your work - except all the crazy things.
Hi,
I use treedict more and more to distribute parameters of scientific simulations. However, I regularly get bitten by implicit branch creation. I misspell the name of a branch I want to retrieve, and rather than raising an exception, it gives me a dandling branch, which creates problems when the value is actually used, which can be in some completely different place in the code. Hard to debug.
Moreover, since dandling branches are invisible, I can't even check that dandling branches exist or were accessed, which makes any kind of automatic error-checking on that aspect (eg. unit test) impossible.
Would it be possible to disable the implicit branch creation, without freezing the structure ? For instance, something like :
I looked at the code, but did not find the right combination of flag to make this work.
The text was updated successfully, but these errors were encountered: