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

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all 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 deletions 5 Lib/test/test_xml_etree.py
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 deletions 7 Modules/_elementtree.c
Original file line number Diff line number Diff 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.