Title: xml.etree.ElementTree.SubElement definition is incorrect / inconsistent with C · Issue #144270 · python/cpython · GitHub
Open Graph Title: xml.etree.ElementTree.SubElement definition is incorrect / inconsistent with C · Issue #144270 · python/cpython
X Title: xml.etree.ElementTree.SubElement definition is incorrect / inconsistent with C · Issue #144270 · python/cpython
Description: Bug report Bug description: This code runs fine on Python 3.13.7: import xml.etree.ElementTree as ET x = ET.Element("x") ET.SubElement(x, 0, parent="0") However, Pyright correctly detects a type error in the SubElement call. SubElement h...
Open Graph Description: Bug report Bug description: This code runs fine on Python 3.13.7: import xml.etree.ElementTree as ET x = ET.Element("x") ET.SubElement(x, 0, parent="0") However, Pyright correctly detects a type er...
X Description: Bug report Bug description: This code runs fine on Python 3.13.7: import xml.etree.ElementTree as ET x = ET.Element("x") ET.SubElement(x, 0, parent="0") However, Pyright correct...
Opengraph URL: https://github.com/python/cpython/issues/144270
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"xml.etree.ElementTree.SubElement definition is incorrect / inconsistent with C","articleBody":"# Bug report\n\n### Bug description:\n\nThis code runs fine on Python 3.13.7:\n\n```python\nimport xml.etree.ElementTree as ET\nx = ET.Element(\"x\")\nET.SubElement(x, 0, parent=\"0\")\n```\n\nHowever, Pyright *correctly* detects a type error in the `SubElement` call. `SubElement` has this Python signature:\n\n```python\ndef SubElement(parent, tag, attrib={}, **extra):\n```\n\nThe `parent` parameter has already been assigned, so this *should* fail. I believe the fact that it doesn't is because it's actually using a C implementation, and the C implementation has *this* type signature:\n\n```\ndef SubElement(parent, tag, /, attrib={}, **extra):\n```\n\nWhich *does* allow specifying `parent=\"0\"`.\n\nSo I think the solution is just to add that `/` into the Python code.\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-144313\n* gh-144845\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Timmmm","@type":"Person","name":"Timmmm"},"datePublished":"2026-01-27T10:49:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/144270/cpython/issues/144270"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2841c9bf-3c0d-1d67-714d-dba3845be85c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E484:291A44:E4926B:135986D:6A5172A3 |
| html-safe-nonce | 5b8ebf44d5047975b38731839278ed007736307348b9646e293fcdb14afbd0e6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDg0OjI5MUE0NDpFNDkyNkI6MTM1OTg2RDo2QTUxNzJBMyIsInZpc2l0b3JfaWQiOiI2NDU4MTU2NzQzNTM3MDI5Nzk1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fabed83e1a0a95430261f3e786724be2c56ac2ee1259d21517485abf52d4f124 |
| hovercard-subject-tag | issue:3859978654 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/144270/issue_layout |
| twitter:image | https://opengraph.githubassets.com/86caf1987865f0793e35c81fd57c037d582c20597b62eb07aae6550110b96fe4/python/cpython/issues/144270 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/86caf1987865f0793e35c81fd57c037d582c20597b62eb07aae6550110b96fe4/python/cpython/issues/144270 |
| og:image:alt | Bug report Bug description: This code runs fine on Python 3.13.7: import xml.etree.ElementTree as ET x = ET.Element("x") ET.SubElement(x, 0, parent="0") However, Pyright correctly detects a type er... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Timmmm |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b19955a9dd40fd99462443f7911b522d7216776a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width