Almost, he is also converting ordinary dicts that get added as items to his own Dict class to enable you to keep using this syntax further down the tree, so you'd need a small wrapper around __setitem__.
But yes, the idea of storing everything twice (once as an item and once as an attribute) just so you can unconditionally add defaults in __getattr__ is… bizarre and will break things horribly as soon as you accidentally do something like:
> Almost, he is also converting ordinary dicts that get added as items to his own Dict class
You are right I dind't notice that before.
But looking at the code it seems that the only permitted values are dict and str?!
> But yes, the idea of storing everything twice (once as an item and once as an attribute)
I don't get that, you don't store things twice and nothing breaks, at least with the example code I wrote above. Try:
The only permitted keys are str, and the rest are silently ignored. This is another bug in his implementation (only the first line should be indented, but both are).
Your code is fine - you're not storing everything twice, but he is (in _set_both()).
But yes, the idea of storing everything twice (once as an item and once as an attribute) just so you can unconditionally add defaults in __getattr__ is… bizarre and will break things horribly as soon as you accidentally do something like: