Title: gh-144270: make SubElement parent and tag positional-only by NekoAsakura · Pull Request #144845 · python/cpython · GitHub
Open Graph Title: gh-144270: make SubElement parent and tag positional-only by NekoAsakura · Pull Request #144845 · python/cpython
X Title: gh-144270: make SubElement parent and tag positional-only by NekoAsakura · Pull Request #144845 · python/cpython
Description: Issue: #144270 Make parent and tag positional-only in xml.etree.ElementTree.SubElement to match the C accelerator. The C implementation (_elementtree.SubElement) uses PyArg_ParseTuple, which inherently makes parent and tag positional-only. The Python fallback used def SubElement(parent, tag, attrib={}, **extra): which allowed parent and tag as keyword arguments. This inconsistency meant SubElement(parent=e, tag="x") worked only when the C accelerator was unavailable. Fix: add / after tag → def SubElement(parent, tag, /, attrib={}, **extra): Changes Lib/xml/etree/ElementTree.py: add / to SubElement signature Lib/test/test_xml_etree.py: add test_subelement covering positional-only enforcement, keyword attrib, and kwargs-as-XML-attributes parity Doc/library/xml.etree.elementtree.rst: update signature and add versionchanged:: 3.15 Note Element.__init__ has the same Python/C signature mismatch — tag is positional-only in the C version (PyArg_ParseTuple at _elementtree.c:419) but accepts keywords in the Python fallback (ElementTree.py:167). I will create a separate issue for that to keep this PR focused. cpython/Lib/xml/etree/ElementTree.py Line 167 in 23c488d def __init__(self, tag, attrib={}, **extra): cpython/Modules/_elementtree.c Lines 419 to 420 in 23c488d if (!PyArg_ParseTuple(args, "O|O!:Element", &tag, &PyDict_Type, &attrib)) return -1; Issue: gh-144270 📚 Documentation preview 📚: https://cpython-previews--144845.org.readthedocs.build/
Open Graph Description: Issue: #144270 Make parent and tag positional-only in xml.etree.ElementTree.SubElement to match the C accelerator. The C implementation (_elementtree.SubElement) uses PyArg_ParseTuple, which inhere...
X Description: Issue: #144270 Make parent and tag positional-only in xml.etree.ElementTree.SubElement to match the C accelerator. The C implementation (_elementtree.SubElement) uses PyArg_ParseTuple, which inhere...
Opengraph URL: https://github.com/python/cpython/pull/144845
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2de4def5-1021-c990-8d66-212f41b2f811 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9512:32DCA7:1DB7DD:28C617:6A513326 |
| html-safe-nonce | 809e7759f396a7fc75ed8feb6cf748760700894374f919a810e4a723a69f2888 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTEyOjMyRENBNzoxREI3REQ6MjhDNjE3OjZBNTEzMzI2IiwidmlzaXRvcl9pZCI6IjgzMTA1MzkyMTMzNDE0NTgzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aee67f6f584ebc83777d51f4b4af81c2b803ed204d103f88748b3c270c465f01 |
| hovercard-subject-tag | pull_request:3287292545 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/144845/files |
| twitter:image | https://avatars.githubusercontent.com/u/72689291?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/72689291?s=400&v=4 |
| og:image:alt | Issue: #144270 Make parent and tag positional-only in xml.etree.ElementTree.SubElement to match the C accelerator. The C implementation (_elementtree.SubElement) uses PyArg_ParseTuple, which inhere... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e840f405b2718e8f2d55aafa9ff27dbce17e29d0c253011d05ea0fea3c78baff |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4ae6027e8ba70c79dc08249bb6cdc1a09d788496 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width