Skip to content

Element has no ancestor with line number. #24

@christianbundy

Description

@christianbundy

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions