mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-35013: Add more type checks for children of Element. (GH-9944)
It is now guarantied that children of xml.etree.ElementTree.Element are Elements (at least in C implementation). Previously methods __setitem__(), __setstate__() and __deepcopy__() could be used for adding non-Element children.
This commit is contained in:
parent
68def052dc
commit
f081fd8303
3 changed files with 71 additions and 50 deletions
|
@ -217,11 +217,11 @@ class Element:
|
|||
return self._children[index]
|
||||
|
||||
def __setitem__(self, index, element):
|
||||
# if isinstance(index, slice):
|
||||
# for elt in element:
|
||||
# assert iselement(elt)
|
||||
# else:
|
||||
# assert iselement(element)
|
||||
if isinstance(index, slice):
|
||||
for elt in element:
|
||||
self._assert_is_element(elt)
|
||||
else:
|
||||
self._assert_is_element(element)
|
||||
self._children[index] = element
|
||||
|
||||
def __delitem__(self, index):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue