-
Notifications
You must be signed in to change notification settings - Fork 89
Confusing behavior when using star globs and list indexing #166
Description
When using dpath.util.search retrieves an empty list, it won't include it in the result:
>>> import dpath.util >>> a = {'a': {'b': []}} >>> b = {'a': {'b': [1, 2, 3]}} >>> dpath.util.search(a, 'a/b/*') # expecting {'a': {'b': []}} here {} >>> dpath.util.search(b, 'a/b/*', afilter=x > 3 if isinstance(x, int) else True) # should again give {'a': {'b': []}} {} >>> dpath.util.search(a, 'a/b') {'a': {'b': []}}
I find this behaviour counterintuitive: I tend to "pronounce" the star as "give me all items in this location". Hence if the item is an empty list, then I want that empty list. Am I misunderstanding something here? What would be the expected behaviour? Also, the final call illustrates something that I find particularly strange here: I would think of both globs to give the same results, but they don't seem to do so.
A second confusing thing seems to be the handling of numeric indexes for lists:
>>> dpath.util.search(b, 'a/b/0') {'a': {'b': [1]}} >>> dpath.util.search(b, 'a/b/-1') # expecting {'a': {'b': [3]}} here. {}
How would I pass negative indexes? Is that supported at all?
Metadata
Metadata
Assignees
Type
Fields
Give feedbackNo fields configured for issues without a type.