GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-144846: make Element tag positional-only by NekoAsakura · Pull Request #144876 · python/cpython

Conversation

@NekoAsakura

@NekoAsakura NekoAsakura commented Feb 16, 2026 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Make tag positional-only in xml.etree.ElementTree.Element.__init__ to match the C accelerator.

The C implementation (_elementtree.Element) uses PyArg_ParseTuple, which inherently makes tag positional-only. The Python fallback used def __init__(self, tag, attrib={}, **extra): which allowed tag as a keyword argument. This inconsistency meant Element(tag="foo") worked only when the C accelerator was unavailable.

Same pattern as gh-144270 (SubElement).

Fix: add / after tag → def __init__(self, tag, /, attrib={}, **extra):

Changes

  • Lib/xml/etree/ElementTree.py: add / to Element.__init__ signature
  • Lib/test/test_xml_etree.py: add test_element_init 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
  • Issue: Element.__init__ tag parameter has positional-only inconsistency #144846

📚 Documentation preview 📚: https://cpython-previews--144876.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added the awaiting review label Feb 16, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Feb 16, 2026
Element.__init__ tag parameter has positional-only inconsistency #144846
Closed
brijkapadia
brijkapadia reviewed Feb 16, 2026
View reviewed changes
Comment thread Lib/test/test_xml_etree.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Feb 16, 2026

Copy link
Copy Markdown

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 skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NekoAsakura

NekoAsakura commented Feb 16, 2026

Copy link
Copy Markdown
Member Author

@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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aisk

aisk commented Feb 16, 2026

Copy link
Copy Markdown
Member

This PR changes the behavior of the public APIs and may affect users' code, so a news entry is required. #144845 is the same.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NekoAsakura
pythongh-144846: make Element tag positional-only
aa2871b
@NekoAsakura
NekoAsakura force-pushed the gh-144846-element-init-positional-only branch from 6f67486 to aa2871b Compare February 16, 2026 15:43
@NekoAsakura

NekoAsakura commented Feb 16, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reminder! I've added news entries to both PRs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brijkapadia

brijkapadia commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

@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?

Left small suggestion

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka approved these changes Feb 19, 2026
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/xml.etree.elementtree.rst
an optional dictionary, containing element attributes. *extra* contains
additional attributes, given as keyword arguments.

.. versionchanged:: 3.15

@serhiy-storchaka serhiy-storchaka Feb 19, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. versionchanged:: 3.15
.. versionchanged:: next

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_xml_etree.py

# 'attrib' can be passed as keyword
e = ET.Element('e', attrib={'key': 'value'})
self.assertEqual(e.get('key'), 'value')

@serhiy-storchaka serhiy-storchaka Feb 19, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe test also the attribute name 'attrib'?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Feb 19, 2026
@NekoAsakura NekoAsakura mentioned this pull request Feb 19, 2026
gh-144270: make SubElement parent and tag positional-only #144845
Merged
@NekoAsakura

NekoAsakura commented Mar 30, 2026

Copy link
Copy Markdown
Member Author

Closing in favour of #144845, which already includes this change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NekoAsakura NekoAsakura closed this Mar 30, 2026
@NekoAsakura
NekoAsakura deleted the gh-144846-element-init-positional-only branch March 30, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
+1 more reviewer
@brijkapadia brijkapadia brijkapadia left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting merge

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@NekoAsakura @aisk @brijkapadia @serhiy-storchaka
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.