Bug report
Bug description:
Element.__init__ has the same Python/C signature inconsistency as SubElement (gh-144270).
Python fallback:
|
def __init__(self, tag, attrib={}, **extra): |
tag accepts keyword arguments: Element(tag="foo") works.
C accelerator:
|
if (!PyArg_ParseTuple(args, "O|O!:Element", &tag, &PyDict_Type, &attrib)) |
|
return -1; |
PyArg_ParseTuple only parses positional args, so tag is positional-only. Element(tag="foo") raises TypeError.
Proposed fix
- def __init__(self, tag, attrib={}, **extra):
+ def __init__(self, tag, /, attrib={}, **extra):
Same pattern as the SubElement fix in gh-144270.
Reproduce
import sys, importlib
import xml.etree.ElementTree as ET
root = ET.Element("root")
try:
ET.Element(tag="foo")
except TypeError:
print("C rejects Element(tag=...)")
sys.modules['_elementtree'] = None
importlib.reload(ET)
e = ET.Element(tag="foo")
print(f"pure-python accepted it: {e.tag}")
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
Element.__init__has the same Python/C signature inconsistency as SubElement (gh-144270).Python fallback:
cpython/Lib/xml/etree/ElementTree.py
Line 167 in 23c488d
tag accepts keyword arguments: Element(tag="foo") works.
C accelerator:
cpython/Modules/_elementtree.c
Lines 419 to 420 in 23c488d
PyArg_ParseTuple only parses positional args, so tag is positional-only. Element(tag="foo") raises TypeError.
Proposed fix
Same pattern as the SubElement fix in gh-144270.
Reproduce
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs