gh-144846: make Element tag positional-only by NekoAsakura · Pull Request #144876 · python/cpython
Make tag positional-only in xml.etree.ElementTree.Element.__init__ to match the C accelerator.
The C implementation (_elementtree.Element) uses PyArg_ParseTuple, which inherently makes tag positional-only. The Python fallback used def __init__(self, tag, attrib={}, **extra): which allowed tag as a keyword argument. This inconsistency meant Element(tag="foo") worked only when the C accelerator was unavailable.
Same pattern as gh-144270 (SubElement).
Fix: add / after tag → 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.15
📚 Documentation preview 📚: https://cpython-previews--144876.org.readthedocs.build/