gh-144846: make Element tag positional-only#144876
Open
NekoAsakura wants to merge 1 commit intopython:mainfrom
Open
gh-144846: make Element tag positional-only#144876NekoAsakura wants to merge 1 commit intopython:mainfrom
NekoAsakura wants to merge 1 commit intopython:mainfrom
Conversation
bkap123
reviewed
Feb 16, 2026
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Author
Member
|
This PR changes the behavior of the public APIs and may affect users' code, so a news entry is required. #144845 is the same. |
6f67486 to
aa2871b
Compare
Author
|
Thanks for the reminder! I've added news entries to both PRs. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make
tagpositional-only inxml.etree.ElementTree.Element.__init__to match the C accelerator.The C implementation (
_elementtree.Element) usesPyArg_ParseTuple, which inherently makestagpositional-only. The Python fallback useddef __init__(self, tag, attrib={}, **extra):which allowedtagas a keyword argument. This inconsistency meantElement(tag="foo")worked only when the C accelerator was unavailable.Same pattern as gh-144270 (
SubElement).Fix: add
/aftertag→def __init__(self, tag, /, attrib={}, **extra):Changes
Lib/xml/etree/ElementTree.py: add/toElement.__init__signatureLib/test/test_xml_etree.py: addtest_element_initcovering positional-only enforcement, keyword attrib, and kwargs-as-XML-attributes parityDoc/library/xml.etree.elementtree.rst: update signature and addversionchanged:: 3.15Element.__init__tag parameter has positional-only inconsistency #144846📚 Documentation preview 📚: https://cpython-previews--144876.org.readthedocs.build/