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 returns IndexError where Resolver.get does not #125

Closed
zegervdv opened this issue Feb 19, 2020 · 6 comments
Closed

Resolver.glob returns IndexError where Resolver.get does not #125

zegervdv opened this issue Feb 19, 2020 · 6 comments

Comments

@zegervdv
Copy link
Contributor

Example:

from anytree import Node
top = Node("top", parent=None)
sub0 = Node("sub0", parent=top)
sub0sub0 = Node("sub0sub0", parent=sub0)
sub0sub1 = Node("sub0sub1", parent=sub0)
sub1 = Node("sub1", parent=top)

from anytree import Resolver
r = Resolver('name')

Getting the top node from sub0:

>>> r.get(sub0, '..')
Node('/top')

Using glob:

>>> r.glob(sub0, '..')
.../anytree/resolver.py in __glob(self, node, parts)
    165     def __glob(self, node, parts):
    166         nodes = []
--> 167         name = parts[0]
    168         remainder = parts[1:]
    169         # handle relative

IndexError: list index out of range
@c0fec0de
Copy link
Owner

Good catch. This is a bug. I will fix it. Will be fixed in 1.8.1

c0fec0de added a commit that referenced this issue Feb 19, 2020
@zegervdv
Copy link
Contributor Author

Great! Just tested with the fix and it works.

@MHendricks
Copy link

This issue seems to be back in 2.8.0 for the original relative case and when directly referencing the top node.

from anytree import Node, Resolver
top = Node("top", parent=None)
sub0 = Node("sub0", parent=top)
r = Resolver('name')

For sub0

>>> print(r.get(sub0, '..'))
Node('/top')
>>> print(r.glob(sub0, '..'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python37\lib\site-packages\anytree\resolver.py", line 147, in glob
    return self.__glob(node, parts)
  File "C:\Program Files\Python37\lib\site-packages\anytree\resolver.py", line 171, in __glob
    nodes += self.__glob(node.parent, remainder)
  File "C:\Program Files\Python37\lib\site-packages\anytree\resolver.py", line 167, in __glob
    name = parts[0]
IndexError: list index out of range

Referencing the top level in the glob.

>>> print(r.get(top, '/top'))
Node('/top')
>>> print(r.glob(top, '/top'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python37\lib\site-packages\anytree\resolver.py", line 147, in glob
    return self.__glob(node, parts)
  File "C:\Program Files\Python37\lib\site-packages\anytree\resolver.py", line 167, in __glob
    name = parts[0]
IndexError: list index out of range

@zegervdv
Copy link
Contributor Author

It hasn't been released yet. The 1.8.1 above was a typo.

@c0fec0de
Copy link
Owner

c0fec0de commented Jul 1, 2021

Will release 3.0.0 soon

@c0fec0de c0fec0de closed this as completed Jul 1, 2021
@ghost
Copy link

ghost commented Jun 26, 2023

Hey guys, I'm curious if this bug was ever patched. The repo still says it's on version 2.8.0

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

3 participants