gh-144846: make Element tag positional-only#144876
gh-144846: make Element tag positional-only#144876NekoAsakura wants to merge 1 commit intopython:mainfrom
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 |
|
@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? |
|
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
|
Thanks for the reminder! I've added news entries to both PRs. |
Left small suggestion |
| an optional dictionary, containing element attributes. *extra* contains | ||
| additional attributes, given as keyword arguments. | ||
|
|
||
| .. versionchanged:: 3.15 |
There was a problem hiding this comment.
| .. versionchanged:: 3.15 | |
| .. versionchanged:: next |
|
|
||
| # 'attrib' can be passed as keyword | ||
| e = ET.Element('e', attrib={'key': 'value'}) | ||
| self.assertEqual(e.get('key'), 'value') |
There was a problem hiding this comment.
Maybe test also the attribute name 'attrib'?
|
Closing in favour of #144845, which already includes this change. |
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/