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-87613: Supprt **kwargs in AC VC and use for xml.etree.ElementTree.Element by cmaloney · Pull Request #161597 · python/cpython

Conversation

@cmaloney

@cmaloney cmaloney commented Nov 8, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Add working code generation for @vectorcall with **kwargs. The first commit adds support to libclinic converters to get keyword args from stack form rather than a dict. When there are no keyword arguments avoid creating a dictionary.

Exercise that code generation with xml.etree.ElementTree.Element. This adds a small behavior change in that non-string keyword arguments will raise TypeError rather than succeeding. Such keys can still be passed in using attrib. @text_signature keeps the documented (tag, /, attrib={}, **extra): attrib can still be passed by keyword, which the impl pops from extra.

Merging the keywords into the attributes now copies them with PyDict_Copy() instead of PyDict_New() plus PyDict_Update(), and pops attrib with _Py_ID(attrib) rather than creating a string per call; SubElement shares that helper.

pyperf microbenchmark (PGO+LTO, run serially):

Benchmark base Element
E('a', x='1') 116 ns 76.3 ns: 1.52x faster
E('a') 42.6 ns 28.2 ns: 1.51x faster
E('a', attrib=d) 122 ns 82.8 ns: 1.47x faster
E('a', d) 73.8 ns 53.6 ns: 1.38x faster
SE(E('p'), 'a', x='1') 161 ns 120 ns: 1.35x faster
E('a', d, y='2') 102 ns 80.3 ns: 1.27x faster
S('a') 49.4 ns 39.8 ns: 1.24x faster

Benchmark code:

import pyperf

runner = pyperf.Runner()
setup = ("from _elementtree import Element as E, SubElement as SE\n"
         "d = {'x': '1'}\n"
         "class S(E): pass")
for stmt in ["E('a')", "E('a', d)", "E('a', x='1')", "E('a', d, y='2')",
             "E('a', attrib=d)", "S('a')", "SE(E('p'), 'a', x='1')"]:
    runner.timeit(stmt, stmt, setup)
  • Issue: Generate vectorcall code to parse arguments using Argument Clinic #87613

Sorry, something went wrong.

Uh oh!

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

All reactions
cmaloney and others added 2 commits November 7, 2026 16:51
@cmaloney @claude
pythongh-87613: Support **kwargs in Argument Clinic vectorcall
0461451
`@vectorcall` with `**kwargs` always delegated to the keyword helper,
which only reads a kwargs dict, so it couldn't be generated.  The
vectorcall now parses positionals with the shared positional emitter and
builds the dict from kwnames only when there are keywords, otherwise
passing NULL, as the tuple parser does.

The `*args` and `**kwargs` parsers take the calling convention explicitly
rather than reading `self.fastcall`, which describes the Python-visible
entry point having stack style args, not the vectorcall.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmaloney @claude
pythongh-87613: Use Argument Clinic vectorcall for xml.etree.ElementT…
0f32147
…ree.Element

xml.etree.ElementTree.Element gains a generated vectorcall.  Keys that
are not strings in `**extra` now raise TypeError on a normal call, as
the Python implementation already did, because vectorcall keywords must
be strings; an explicit `__init__` call and subclasses still accept them.

`@text_signature` keeps the documented `(tag, /, attrib={}, **extra)`:
`attrib` can still be passed by keyword, which the impl pops from `extra`.

Merging the keywords into the attributes now copies them with
PyDict_Copy() instead of PyDict_New() plus PyDict_Update(), and pops
`attrib` with `_Py_ID(attrib)` rather than creating a string per call;
SubElement shares that helper.

pyperf microbenchmark (PGO+LTO, run serially):

| Benchmark              | base    | Element               |
|------------------------|:-------:|:---------------------:|
| E('a', x='1')          | 116 ns  | 76.3 ns: 1.52x faster |
| E('a')                 | 42.6 ns | 28.2 ns: 1.51x faster |
| E('a', attrib=d)       | 122 ns  | 82.8 ns: 1.47x faster |
| E('a', d)              | 73.8 ns | 53.6 ns: 1.38x faster |
| SE(E('p'), 'a', x='1') | 161 ns  | 120 ns: 1.35x faster  |
| E('a', d, y='2')       | 102 ns  | 80.3 ns: 1.27x faster |
| S('a')                 | 49.4 ns | 39.8 ns: 1.24x faster |

Benchmark code:

```python
import pyperf

runner = pyperf.Runner()
setup = ("from _elementtree import Element as E, SubElement as SE\n"
         "d = {'x': '1'}\n"
         "class S(E): pass")
for stmt in ["E('a')", "E('a', d)", "E('a', x='1')", "E('a', d, y='2')",
             "E('a', attrib=d)", "S('a')", "SE(E('p'), 'a', x='1')"]:
    runner.timeit(stmt, stmt, setup)
```

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmaloney
cmaloney requested review from AA-Turner and erlend-aasland as code owners November 8, 2026 01:54
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 8, 2026
@cmaloney cmaloney changed the title Supprt **kwargs in AC VC and use for xml.etree.ElementTree.Element gh-87613: Supprt **kwargs in AC VC and use for xml.etree.ElementTree.Element Nov 8, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 8, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Nov 8, 2026
Generate vectorcall code to parse arguments using Argument Clinic #87613
Open
cmaloney and others added 2 commits November 7, 2026 17:57
@cmaloney @claude
pythongh-87613: Check the attrib copy explicitly in get_attrib_from_k…
e49ac09
…eywords

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmaloney @claude
pythongh-87613: Allow 'as' on Argument Clinic **kwargs parameters
285bfdd
`*args as name` already set the C name; `**kwargs as name` failed to
parse because the 'as' regex only allowed a single leading star.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

awaiting core review type-feature A feature request or enhancement

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.

1 participant

@cmaloney
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 01402520 — 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.