Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144270: Fix xml.etree.ElementTree.SubElement signature inconsistency#144313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletionsLib/test/test_xml_etree.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4764,6 +4764,11 @@ def test_deprecated_version(self):
) as cm:
getattr(ET, "VERSION")
self.assertEqual(cm.filename, __file__)

def test_subelement_parent_positional_only(self):
root = ET.Element("root")
with self.assertRaises(TypeError):
ET.SubElement(root, "child", parent="0")


# --------------------------------------------------------------------
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Fix xml.etree.ElementTree.SubElement to reject ``parent`` passed as a keyword argument, making the Python signature consistent with the C implementation.
7 changes: 7 additions & 0 deletionsModules/_elementtree.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -611,6 +611,13 @@ subelement(PyObject *self, PyObject *args, PyObject *kwds)
ElementObject* parent;
PyObject* tag;
PyObject* attrib = NULL;
if (kwds && PyDict_Contains(kwds, PyUnicode_FromString("parent"))) {
PyErr_SetString(
PyExc_TypeError,
"SubElement() got some positional-only arguments passed as keyword arguments"
);
return NULL;
}
if (!PyArg_ParseTuple(args, "O!O|O!:SubElement",
st->Element_Type, &parent, &tag,
&PyDict_Type, &attrib)) {
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp