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 — `Element.__init__` tag parameter has positional-only inconsistency · Issue #144846 · python/cpython

Element.__init__ tag parameter has positional-only inconsistency #144846

New issue
Copy link
New issue
Copy link
Closed
Closed
Element.__init__ tag parameter has positional-only inconsistency#144846
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@NekoAsakura
NekoAsakura
opened on Feb 15, 2026
Issue body actions

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):

tag accepts keyword arguments: Element(tag="foo") works.

C accelerator:

cpython/Modules/_elementtree.c

Lines 419 to 420 in 23c488d

if (!PyArg_ParseTuple(args, "O|O!:Element", &tag, &PyDict_Type, &attrib))
return -1;

PyArg_ParseTuple only parses positional args, so tag is positional-only. Element(tag="foo") raises TypeError.

Proposed fix

-    def __init__(self, tag, attrib={}, **extra):
+    def __init__(self, tag, /, attrib={}, **extra):

Same pattern as the SubElement fix in gh-144270.

Reproduce

import sys, importlib
import xml.etree.ElementTree as ET

root = ET.Element("root")

try:
    ET.Element(tag="foo")
except TypeError:
    print("C rejects Element(tag=...)")

sys.modules['_elementtree'] = None
importlib.reload(ET)

e = ET.Element(tag="foo")
print(f"pure-python accepted it: {e.tag}") 

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-144846: make Element tag positional-only #144876

Activity

  1. NekoAsakura
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Feb 15, 2026
  2. brianschubert
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-XML
    on Feb 15, 2026
  3. brijkapadia commented on Feb 16, 2026

    @brijkapadia
    brijkapadia
    on Feb 16, 2026
    Contributor
    More actions

    @NekoAsakura Do you want to create a PR or could I work on it?

  4. NekoAsakura commented on Feb 16, 2026

    @NekoAsakura
    NekoAsakura
    on Feb 16, 2026
    MemberAuthor
    More actions

    Hi @bkap123 , cheers for the shout! I've already got the fix ready to go. I’ll whip a PR up now.

    Reacted by Brij Kapadia
  5. NekoAsakura
    added 2 commits that reference this issue on Feb 16, 2026

    pythongh-144846: make Element tag positional-only

    e0895a4

    pythongh-144846: make Element tag positional-only

    aa2871b
  6. NekoAsakura
    closed this as completedon Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.