This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add more type checks for children of xml.etree.ElementTree.Element
Type: behavior Stage: resolved
Components: Library (Lib), XML Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: eli.bendersky, scoder, serhiy.storchaka
Priority: normal Keywords: patch

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:07adminsetgithub: 79194
2018-10-19 09:34:28serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg328035

stage: patch review -> resolved
2018-10-19 09:13:07serhiy.storchakasetmessages: + msg328033
2018-10-19 07:30:14scodersetmessages: + msg328032
2018-10-18 07:04:25serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request9295
2018-10-18 06:56:21serhiy.storchakacreate