|
Meta tags:
description=In xml.etree.ElementTree.Element replace PyArg_ParseTuple with Argument Clinic and add 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. Arity errors use the generated wording ( Element expected at most 2 arguments, got 3 ).
@text_signature keeps the documented (tag, /, attrib= , **extra); the / is new in the signature, tag was already positional-only. 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 )
121 ns
78.7 ns: 1.53x faster
E( a , attrib=d)
123 ns
86.1 ns: 1.43x faster
E( a )
41.9 ns
29.4 ns: 1.43x faster
E( a , d)
75.8 ns
55.6 ns: 1.36x faster
SE(E( p ), a , x= 1 )
161 ns
120 ns: 1.34x faster
build()
22.2 us
17.2 us: 1.29x faster
S( a )
49.6 ns
40.8 ns: 1.22x faster
E( a , d, y= 2 )
103 ns
85.4 ns: 1.21x faster
Not significant: fromstring(doc) (C parser, unchanged path).
Benchmark code:
import pyperf
runner = pyperf.Runner()
setup =
from xml.etree.ElementTree import Element as E, SubElement as SE, fromstring
d = x : 1
class S(E): pass
def build():
root = E( root )
for i in range(100):
c = SE(root, item , id= 1 )
c.append(E( v , d))
return root
doc = root + item id= 1 v x= 1 / /item * 100 + /root
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 ) ,
build() , fromstring(doc) ]:
runner.timeit(stmt, stmt, setup)
This is a rebuild of gh-161597 on top of the landed AC VC generation work. cc: @asvetlov
Issue: gh-162350;
Headings (most frequently used words):
uh, oh, for, navigation, gh, 162350, use, argument, clinic, vectorcall, xml, etree, elementtree, element, 162653, are, footer, you, diff, view, menu, repository, there, no, files, selected, viewing, sure, want, to, change, the, base, filter, by, extension,
Text of the page (most frequently used words):
file (43), attrib (37), #element (24), the (23), this (20), github (20), tag (19), and (18), pyobject (18), show (16), line (15), open (15), expand (15), include (15), diff (14), for (14), you (13), that (13), all (13), loading (13), clinic (13), kwds (13), reload (12), files (12), null (12), return (12), self (12), hidden (12), characters (12), unicode (12), applied (11), comments (11), change (11), code (11), text (11), not (10), while (10), learn (10), about (10), view (10), number (10), more (9), internal (9), please (8), changes (8), there (8), generated (8), are (8), load (8), desktop (8), delete (8), edit (8), _elementtree (8), deletions (8), bidirectional (8), 162350 (8), suggestion (7), cannot (7), suggestions (7), was (7), error (7), page (7), retry (7), extra (7), its (7), xml (7), struct_for_id (7), sign (7), 2026 (6), default (6), py_newref (6), self_elem (6), may (6), review (6), etree (6), commits (6), security (5), check (5), from (5), oops (5), something (5), went (5), wrong (5), some (5), modules (5), down (5), static (5), tail (5), class (5), argument (5), vectorcall (5), what (5), elementtree (5), issue (5), cmaloney (5), base (5), your (5), can (4), pull (4), rendered (4), how (4), customized (4), appear (4), additions (4), element_init (4), attributes (4), length (4), _set_joined_ptr (4), py_none (4), args (4), input (4), original (4), contains (4), interpreted (4), compiled (4), differently (4), than (4), appears (4), below (4), editor (4), reveals (4), python (4), next (4), rst (4), addition (4), nbsp (4), use (4), support (4), copilot (4), community (3), navigation (3), request (3), must (3), add (3), batch (3), commit (3), name (3), attribute (3), want (3), implementation (3), already (3), py_decref (3), elementobject (3), misc (3), news (3), library (3), 7lkjhs (3), def (3), with (3), lib (3), test (3), test_xml_etree (3), pycore_unicodeobject_generated (3), pycore_runtime_init_generated (3), pycore_global_strings (3), pycore_global_objects_fini_generated (3), hide (3), whitespace (3), filter (3), 162653 (3), branch (3), refname (3), account (3), quality (3), another (3), tab (3), window (3), refresh (3), session (3), developers (3), changelog (3), customer (3), enterprise (3), grade (3), features (3), build (3), contact (2), status (2), privacy (2), terms (2), footer (2), merge (2), outdated (2), single (2), one (2), viewing (2), toggle (2), 104 (2), py_tp_init (2), element_getsetlist (2), pytype_slot (2), element_slots (2), py_tp_doc (2), void (2), element_doc (2), child (2), example (2), form (2), given (2), keyword (2), arguments (2), containing (2), additional (2), optional (2), dictionary (2), truly (2), empty (2), should (2), both (2), subelements (2), means (2), reference (2), interface (2), py_xsetref (2), create_extra (2), dict (2), end (2), output (2), start (2), object (2), pydict_update (2), _pydict_copyasdict (2), get_attrib_from_keywords (2), _py_id (2), keys (2), typeerror (2), 3027 (2), 327 (2), selected (2), apply (2), split (2), unified (2), failed (2), jump (2), extension (2), nov (2), select (2), tree (2), old (2), could (2), tags (2), branches (2), main (2), insights (2), projects (2), actions (2), repository (2), cpython (2), signed (2), universe (2), training (2), integrations (2), stories (2), center (2), documentation (2), business (2), fixes (2), products (2), secret (2), perform, action, time, share, personal, information, manage, cookies, docs, inc, right, now, back, later, queued, multi, pending, reviews, has, been, marked, resolved, existing, order, create, valid, applying, deleted, lines, supported, only, per, subset, closed, invalid, because, were, made, annotations, notes, 102, py_sq_length, element_length, py_tp_new, element_new, py_tp_alloc, pytype_genericalloc, py_tp_vectorcall, _elementtree_element_vectorcall, _elementtree_element___init__, py_tp_getset, py_tp_members, element_members, py_tp_methods, element_methods, 4482, 4484, py_tp_getattro, pyobject_genericgetattr, py_tp_repr, element_repr, py_tp_dealloc, element_dealloc, _elementtree_element___init____doc__, pydoc_strvar, 4453, 4474, pygetsetdef, replace, objects, pointed, py_xdecref, 460, 481, is_empty_dict, 447, 470, frozendict, pyerr_format, pyexc_typeerror, pyanydict_check, pyarg_parsetuple, 3f81773682edf81e, 58fd874d3a42aca3, _elementtree_element___init___impl, int, c_default, __init__, text_signature, da39a3ee5e6b4b0d, 6c83ea832d2b0ef1, 413, 414, xmlparser, xmlparserobject, clinic_state, xmlparser_type, pydict_copy, pydict_new, else, py_setref, 393, 394, pydict_pop, pydict_popstring, 377, 378, pycore_weakref, ft_clear_weakrefs, pycore_tuple, _pytuple_frompair, pycore_runtime, pycore_pyhash, _py_hashsecret, pycore_dict, pycore_ceval, _py_enterrecursivecall, did, pass, such, instead, raise, exc, non, string, when, calling, zix, wyp, foo, test___init__, qname, key, value, assertraisesregex, keywords, strings, test_extra_keys_must_be_strings, basicelementtest, elementtestcase, unittest, testcase, backtick, autocommit, attr, athrow, ast, struct, _py_global_strings, conversations, clear, filters, viewed, types, keep, 9caa82d, 1352e55, hold, shift, click, range, changed, checks, conversation, 160, wants, into, landable, removed, timeline, become, sure, nothing, found, choose, clicking, agree, our, occasionally, send, related, emails, statement, service, free, maintainers, have, question, project, new, items, requests, issues, message, dismiss, alert, switched, accounts, out, appearance, settings, search, pricing, event, talks, workshops, partners, company, forum, events, webinars, blog, resource, connect, resources, premium, advanced, ons, trust, why, evaluate, see, industries, government, manufacturing, financial, services, healthcare, industry, nonprofits, startups, team, enterprises, stage, businesses, source, latest, improvements, across, place, developer, articles, sponsors, trending, repos, explore, customize, certifications, scanning, leak, prevention, protection, vulnerability, detection, remediation, secure, cloud, development, environments, codespaces, analysis, enforcement, automation, ship, coding, agent, tasks, automated, work, hosting, collaboration, platform, menu, skip, content,
|