gh-144846: make Element tag positional-only#144876
Conversation
|
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 |
Sorry, something went wrong.
|
@bkap123 cheers for the review. While I'm at it, do I need to make the same change over on #144845 (the SubElement one) as well, or is that alright as is? |
Sorry, something went wrong.
|
This PR changes the behavior of the public APIs and may affect users' code, so a news entry is required. #144845 is the same. |
Sorry, something went wrong.
6f67486 to
aa2871b
Compare
February 16, 2026 15:43
|
Thanks for the reminder! I've added news entries to both PRs. |
Sorry, something went wrong.
Left small suggestion |
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM. 👍
Sorry, something went wrong.
|
Closing in favour of #144845, which already includes this change. |
Sorry, something went wrong.
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/