Title: `Element.__init__` tag parameter has positional-only inconsistency · Issue #144846 · python/cpython · GitHub
Open Graph Title: `Element.__init__` tag parameter has positional-only inconsistency · Issue #144846 · python/cpython
X Title: `Element.__init__` tag parameter has positional-only inconsistency · Issue #144846 · python/cpython
Description: 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 def __init__(self, tag, attrib={}, **extra): ...
Open Graph Description: 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 def _...
X Description: 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 def _...
Opengraph URL: https://github.com/python/cpython/issues/144846
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Element.__init__` tag parameter has positional-only inconsistency","articleBody":"# Bug report\n\n### Bug description:\n\n`Element.__init__` has the same Python/C signature inconsistency as SubElement (gh-144270).\n\nPython fallback:\nhttps://github.com/python/cpython/blob/23c488d6197191d355be6733699a295c20806932/Lib/xml/etree/ElementTree.py#L167\ntag accepts keyword arguments: Element(tag=\"foo\") works.\n\nC accelerator:\nhttps://github.com/python/cpython/blob/23c488d6197191d355be6733699a295c20806932/Modules/_elementtree.c#L419-L420\nPyArg_ParseTuple only parses positional args, so tag is positional-only. Element(tag=\"foo\") raises TypeError.\n\n### Proposed fix\n```\n- def __init__(self, tag, attrib={}, **extra):\n+ def __init__(self, tag, /, attrib={}, **extra):\n```\n\nSame pattern as the SubElement fix in gh-144270.\n\n### Reproduce\n```\nimport sys, importlib\nimport xml.etree.ElementTree as ET\n\nroot = ET.Element(\"root\")\n\ntry:\n ET.Element(tag=\"foo\")\nexcept TypeError:\n print(\"C rejects Element(tag=...)\")\n\nsys.modules['_elementtree'] = None\nimportlib.reload(ET)\n\ne = ET.Element(tag=\"foo\")\nprint(f\"pure-python accepted it: {e.tag}\") \n```\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-144876\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/NekoAsakura","@type":"Person","name":"NekoAsakura"},"datePublished":"2026-02-15T18:23:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/144846/cpython/issues/144846"}
| 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:f8cd60bd-607a-9cc3-184d-1d6ddfebded3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DCB4:18F0F4:AD436C:E6E8DD:6A51A7A9 |
| html-safe-nonce | 37944048c594d9073e4f9b76f4298793aa723f295656e3e0195b1f1e8f2a4774 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0I0OjE4RjBGNDpBRDQzNkM6RTZFOEREOjZBNTFBN0E5IiwidmlzaXRvcl9pZCI6IjEyMjIxNjk2MTYyOTEzMDk0ODIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e8b494b610ddafe57ee91dabea356344f2ef2da72f8d3ab1c5725194eadc3965 |
| hovercard-subject-tag | issue:3944627019 |
| 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/144846/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a6efa076ee494365ec0f9dbbb086e73688aa6f97389414b3b4f46c5dfe88d51b/python/cpython/issues/144846 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a6efa076ee494365ec0f9dbbb086e73688aa6f97389414b3b4f46c5dfe88d51b/python/cpython/issues/144846 |
| og:image:alt | 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 def _... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NekoAsakura |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width