summaryrefslogtreecommitdiffstats
path: root/Modules/_elementtree.c
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2012-03-23 12:24:20 (GMT)
committerEli Bendersky <eliben@gmail.com>2012-03-23 12:24:20 (GMT)
commit396e8fcf36480dacaeeeb785a3912a565294d3b7 (patch)
tree173647551cef119cdf7644b8eb009b4a48314995 /Modules/_elementtree.c
parent42243c4dcaee5fe6e680d1ea4b1b615dd0d18b10 (diff)
downloadcpython-396e8fcf36480dacaeeeb785a3912a565294d3b7.zip
cpython-396e8fcf36480dacaeeeb785a3912a565294d3b7.tar.gz
cpython-396e8fcf36480dacaeeeb785a3912a565294d3b7.tar.bz2
Issue #13782: streamline argument type-checking in ET.Element
append, extend and insert now consistently type-check their argument in both the C and Python implementations, and raise TypeError for non-Element argument. Added tests
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r--Modules/_elementtree.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index a50a3e7..e8309df 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -803,6 +803,15 @@ element_extend(ElementObject* self, PyObject* args)
seqlen = PySequence_Size(seq);
for (i = 0; i < seqlen; i++) {
PyObject* element = PySequence_Fast_GET_ITEM(seq, i);
+ if (!PyObject_IsInstance(element, (PyObject *)&Element_Type)) {
+ Py_DECREF(seq);
+ PyErr_Format(
+ PyExc_TypeError,
+ "expected an Element, not \"%.200s\"",
+ Py_TYPE(element)->tp_name);
+ return NULL;
+ }
+
if (element_add_subelement(self, element) < 0) {
Py_DECREF(seq);
return NULL;