Fixing dpath to work for any type of leaf nodes #122
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Given that
leaf
checks for a finite number of types any kind of odd type such as a function or custom object will simply not work in this dictionary. I've suggested an approach based on duck-typing, in which I check if the object has a__getitem__
instead of checking particular type (though I do that too for the case of string)I have a couple of places I wasn't sure about and would love some opinions.
__getitem__
but noitems
orlen
the kvs method breaks. I've kind of just returned an empty iterator here, but it should be accessible via keys and doesn't really need to have a walk run on it if there is no glob for that field. I currently just treat it as a leaf, but maybe this might be addressed with some kind of warning?thing[0]
since it could easily be either an indication the object is mappable, but just uses a custom Exception and might have a len/items implemented. I've let it stand right now, but am open to change.