Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolver.glob on node without children gives IndexError #221

Closed
lverweijen opened this issue Jul 4, 2023 · 3 comments
Closed

Resolver.glob on node without children gives IndexError #221

lverweijen opened this issue Jul 4, 2023 · 3 comments
Assignees
Milestone

Comments

@lverweijen
Copy link

Resolver.glob on node without children gives IndexError.
For non-existing paths it also seems to return nothing instead of an empty iterable, which would be preferred.
When using resolver.get instead it gives correct output instead.

import anytree
node = anytree.Node("root")
resolver = anytree.Resolver()
resolver.glob(node, "/root")  # IndexError, expected [node]
resolver.glob(node, ".")  # IndexError, expected [node]
resolver.glob(node, "")  # IndexError, expected [node]
resolver.glob(node, "..")  # IndexError, expected (ResolverError or just [], but should be consistent with get)
resolver.glob(node, "root")  # Returns nothing, expected []
resolver.glob(node, "bla")  # Returns nothing, expected []
resolver.glob(node, "/bla")  # Returns nothing, expected []

Version used is 2.8.0

@lverweijen
Copy link
Author

lverweijen commented Jul 8, 2023

By the way, can't glob just use the standard library function fnmatchcase in the background (which gives you some features for free)?

@lverweijen
Copy link
Author

Seems to be the same as #125 (but that issue is closed)

@c0fec0de c0fec0de self-assigned this Oct 11, 2023
@c0fec0de
Copy link
Owner

I agree, that the Resolver is a little bit too addicted to exceptions.
I will add a relax attribute, which gives expected empty list.
I will also ensure consistency between get and glob.

@c0fec0de c0fec0de added this to the 2.10.0 milestone Oct 11, 2023
c0fec0de added a commit that referenced this issue Oct 11, 2023
…tc-access-more-child-attributes-than-necessary-when-restricting-maxlevel

fix #221, avoid children attribute access on maxlevel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants