GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Element.itertext() works differently in C and Python implementations · Issue #149571 · python/cpython

Element.itertext() works differently in C and Python implementations #149571

New issue
Copy link
New issue
Copy link
Closed
Closed
Element.itertext() works differently in C and Python implementations#149571
Copy link
Assignees
serhiy-storchaka
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@serhiy-storchaka
serhiy-storchaka
opened on May 8, 2026
Issue body actions

In the Python implementation it returns empty iterator for Comment and ProcessingInstruction. In the C implementation it emits their content.

>>> import xml.etree.ElementTree as ET
>>> list(ET.Comment('comment').itertext())
['comment']

cc @scoder

Linked PRs

  • gh-149571: Make Element.itertext consistent for Comment and ProcessingInstruction #149714
  • gh-149571: Fix the C implementation of Element.itertext() #149929
  • [3.15] gh-149571: Fix the C implementation of Element.itertext() (GH-149929) #150509
  • [3.14] gh-149571: Fix the C implementation of Element.itertext() (GH-149929) #150510
  • [3.13] gh-149571: Fix the C implementation of Element.itertext() (GH-149929) #150511

Activity

  1. serhiy-storchaka
    added
    topic-XML
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on May 8, 2026
  2. StanFromIreland
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on May 8, 2026
  3. hardiksingh5864
    added 4 commits that reference this issue on May 12, 2026

    Add news fragment for pythongh-149571

    6c97311

    pythongh-149571: Make Element.itertext consistent for Comment and Pro…

    2dfd433

    pythongh-149571: Remove the linter issue

    7c8cb36

    pythongh-149571: Fixing the Ci failure

    5df8ef0
  4. serhiy-storchaka commented on May 15, 2026

    @serhiy-storchaka
    serhiy-storchaka
    on May 15, 2026
    MemberAuthor
    More actions

    Let's compare with lxml.

    >>> import lxml.etree as ET
    >>> e = ET.Element('tag')
    >>> e.text = 'text'
    >>> e.append(ET.Comment('comment'))
    >>> list(e.iter())
    [<Element tag at 0x7769b3723540>, <!--comment-->]
    >>> list(e.itertext())
    ['text']
    >>> import xml.etree.ElementTree as ET
    >>> e = ET.Element('tag')
    >>> e.text = 'text'
    >>> e.append(ET.Comment('comment'))
    >>> list(e.iter())
    [<Element 'tag' at 0x7769b368a610>, <Element <function Comment at 0x7769b371b7f0> at 0x7769b3746520>]
    >>> list(e.itertext())
    ['tail', 'comment']

    So I think the correct behavior is to skip comments and processing instructions.

  5. scoder commented on May 16, 2026

    @scoder
    scoder
    on May 16, 2026
    Contributor
    More actions

    So I think the correct behavior is to skip comments and processing instructions.

    I think so, too. Users who collect text from a document wouldn't normally expect comments to be included, let alone processing instructions. Comments are literally meant to keep their content out of the processed document.

  6. serhiy-storchaka
    self-assigned this
    on May 16, 2026
  7. serhiy-storchaka commented on May 17, 2026

    @serhiy-storchaka
    serhiy-storchaka
    on May 17, 2026
    MemberAuthor
    More actions

    #149929 changes the C implementation. It is not exact match of the Python implementation -- they are different if the comment or processing instruction has subelements. But this is a not supported case, it is merely an implementation artifact, so I do not think it is worth to add a code to handle it.

  8. serhiy-storchaka commented on May 17, 2026

    @serhiy-storchaka
    serhiy-storchaka
    on May 17, 2026
    MemberAuthor
    More actions

    This is even explicitly stated in the XML specification, that they are not part of the document's character data.

    https://www.w3.org/TR/xml11/#NT-Comment
    https://www.w3.org/TR/xml11/#NT-PI

  9. serhiy-storchaka
    added 4 commits that reference this issue on May 27, 2026

    gh-149571: Fix the C implementation of Element.itertext() (GH-149929)

    7de4fcd

    [3.13] gh-149571: Fix the C implementation of Element.itertext() (GH-…

    98a9ccb

    [3.14] gh-149571: Fix the C implementation of Element.itertext() (GH-…

    27a18eb

    [3.15] gh-149571: Fix the C implementation of Element.itertext() (GH-…

    d2b10e7
  10. serhiy-storchaka
    closed this as completedon May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @serhiy-storchaka
    serhiy-storchaka

Labels

3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.