Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Confusing behavior when using star globs and list indexing #166

Open
Assignees

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /