Issue 35013: Add more type checks for children of xml.etree.ElementTree.Element (original) (raw)

Issue35013

Created on 2018-10-18 06:56 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9944 merged serhiy.storchaka,2018-10-18 07:04
Messages (4)
msg327939 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-18 06:56
Currently some methods for xml.etree.ElementTree.Element check the type subelements: append(), extend(), insert(). But there are other ways to add non-Element children: __setitem__(), __setstate__(), __deepcopy__(). This could cause crashes later in the C code and required to add numerous type checks for iterating and searching. Since the intention was to prevent adding non-Element children, it is better to check the type every time when add new children.
msg328032 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2018-10-19 07:30
Well, if that's what it takes, then that's what it takes. I'm fine with the change. The (unaccelerated) ET doesn't strictly require it, but a) I can't really see a use case for non-Element classes in the tree, b) pretty much no-one uses plain Python ET anymore, and c) it's better to test the type on input than on usage.
msg328033 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-19 09:13
New changeset f081fd83032be48aefdb1bbcc38ab5deb03785d5 by Serhiy Storchaka in branch 'master': bpo-35013: Add more type checks for children of Element. (GH-9944) https://github.com/python/cpython/commit/f081fd83032be48aefdb1bbcc38ab5deb03785d5
msg328035 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-19 09:34
If there wouldn't type checks in append(), extend() and insert(), I would consider to add the support of duck-typing in iterating and searching. But since non-Elements already are forbidden in the public API, it is better to forbid them everywhere and simplify internal code.
History
Date User Action Args
2022-04-11 14:59:07 admin set github: 79194
2018-10-19 09:34:28 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2018-10-19 09:13:07 serhiy.storchaka set messages: +
2018-10-19 07:30:14 scoder set messages: +
2018-10-18 07:04:25 serhiy.storchaka set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest9295>
2018-10-18 06:56:21 serhiy.storchaka create