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

Element has no ancestor with line number. #24

Open
christianbundy opened this issue May 3, 2021 · 1 comment
Open

Element has no ancestor with line number. #24

christianbundy opened this issue May 3, 2021 · 1 comment

Comments

@christianbundy
Copy link

I'd like to print an attribute, but I'm getting an error:

$ astpath '//Name/@id'
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/astpath/search.py", line 44, in find_in_ast
    linenos = query(
  File "/usr/local/lib/python3.9/site-packages/astpath/search.py", line 12, in lxml_query
    return element.xpath(expression)
AttributeError: 'lxml.etree._ElementUnicodeResult' object has no attribute 'xpath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/astpath", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/astpath/cli.py", line 37, in main
    search(
  File "/usr/local/lib/python3.9/site-packages/astpath/search.py", line 149, in search
    file_matches = find_in_ast(
  File "/usr/local/lib/python3.9/site-packages/astpath/search.py", line 49, in find_in_ast
    raise AttributeError(
AttributeError: Element has no ancestor with line number.

Maybe if it's an ElementUnicodeResult we should just return instead of recursing into element.expath(expression)? Thanks for your work on this project!

@spookylukey
Copy link

This is addressed in my fork: spookylukey/pyastgrep@6fb7521

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