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

xml.etree.ElementTree findall() fails when using custom TreeBuilder #79122

Closed
jackjansen opened this issue Oct 9, 2018 · 5 comments
Closed
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-XML type-bug An unexpected behavior, bug, or error

Comments

@jackjansen
Copy link
Member

BPO 34941
Nosy @jackjansen, @scoder, @serhiy-storchaka, @miss-islington
PRs
  • bpo-34941: Fix searching Element subclasses. #9766
  • [3.7] bpo-34941: Fix searching Element subclasses. (GH-9766) #9867
  • [3.6] bpo-34941: Fix searching Element subclasses. (GH-9766) #9868
  • Files
  • testetns.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2018-10-14.08:41:19.590>
    created_at = <Date 2018-10-09.09:32:14.985>
    labels = ['expert-XML', '3.8', 'type-bug', 'library', '3.7']
    title = 'xml.etree.ElementTree findall() fails when using custom TreeBuilder'
    updated_at = <Date 2018-10-14.08:41:19.589>
    user = 'https://github.com/jackjansen'

    bugs.python.org fields:

    activity = <Date 2018-10-14.08:41:19.589>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2018-10-14.08:41:19.590>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)', 'XML']
    creation = <Date 2018-10-09.09:32:14.985>
    creator = 'jackjansen'
    dependencies = []
    files = ['47859']
    hgrepos = []
    issue_num = 34941
    keywords = ['patch']
    message_count = 5.0
    messages = ['327385', '327388', '327695', '327696', '327698']
    nosy_count = 5.0
    nosy_names = ['jackjansen', 'scoder', 'eli.bendersky', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['9766', '9867', '9868']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34941'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @jackjansen
    Copy link
    Member Author

    When using a TreeBuilder with a custom factory (returning a subclass of Element with some extra functionality) there is an issue with findall().

    XPaths using an indexed predicate no longer work: the findall() result is always empty. The attached test script shows the problem.

    I have analysed this as far as finding that the issue is in ElementPath.prepare_predicate.<locals>.select(), the last one. Specifically, the statement
    elems = list(parent.findall(elem.tag))
    always returns an empty list (if the Element class is subclassed).

    When using Python 2.7 everything works fine. When adding a findall() method to the Element subclass that simply calls Element.findall() everything also works fine. I suspect some issue with the _elementtree C implementation but I don't understand it.

    @jackjansen jackjansen added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 9, 2018
    @jackjansen
    Copy link
    Member Author

    Correction to the last line:
    When using Python 2.7 everything works fine. When adding a findall() method to the Element subclass that simply calls ElementPath.findall() everything also works fine. I suspect some issue with the _elementtree C implementation but I don't understand it.

    @serhiy-storchaka serhiy-storchaka added topic-XML 3.8 only security fixes labels Oct 9, 2018
    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 9, 2018
    @serhiy-storchaka
    Copy link
    Member

    New changeset b11c566 by Serhiy Storchaka in branch 'master':
    bpo-34941: Fix searching Element subclasses. (GH-9766)
    b11c566

    @miss-islington
    Copy link
    Contributor

    New changeset b1c8003 by Miss Islington (bot) in branch '3.7':
    bpo-34941: Fix searching Element subclasses. (GH-9766)
    b1c8003

    @serhiy-storchaka
    Copy link
    Member

    New changeset 7c1c42b by Serhiy Storchaka in branch '3.6':
    [3.6] bpo-34941: Fix searching Element subclasses. (GH-9766) (GH-9868)
    7c1c42b

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-XML type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants