Issue 17989: ElementTree.Element broken attribute setting (original) (raw)

Created on 2013-05-15 22:46 by jwilk, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test-element-setattr.py jwilk,2013-05-15 22:46
Messages (12)
msg189321 - (view) Author: Jakub Wilk (jwilk) Date: 2013-05-15 22:46
Setting attributes on ElementTree.Element objects is broken: it succeeds without exception, but then the following statement fails with AttributeError (unless that statement sets an Element's attribute too): $ python3.3 test-element-setattr.py Hello world!Traceback (most recent call last): File "test-element-setattr.py", line 6, in print('Hello world!') AttributeError: ham2
msg189463 - (view) Author: Joe Stuart (jjstuart) Date: 2013-05-17 15:55
It looks like it's being called from the c extension. I would think it should still throw an exception though? >>> e = etree.Element >>> e.ham = 1 Traceback (most recent call last): File "", line 1, in TypeError: can't set attributes of built-in/extension type 'xml.etree.ElementTree.Element'
msg189474 - (view) Author: Joe Stuart (jjstuart) Date: 2013-05-17 18:04
At the end of ElementTree all of the c accelerators are being imported and it looks like only XMLParser is being used. Here is a patch that only imports XMLParser.
msg189477 - (view) Author: Joe Stuart (jjstuart) Date: 2013-05-17 18:19
This patch should fix the issue of the classes being overwritten by the c accelerated ones.
msg189478 - (view) Author: Joe Stuart (jjstuart) Date: 2013-05-17 19:11
Forgot to update the XMLParser() assignment.
msg189497 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2013-05-18 07:15
Replacement of pure-Python classes by C-accelerated classes is intentional. http://docs.python.org/3.3/library/xml.etree.elementtree.html "Changed in version 3.3: This module will use a fast implementation whenever available. The xml.etree.cElementTree module is deprecated."
msg189515 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-05-18 14:14
Yes, overwriting the Python classes with C classes is not an error, but the original issue is legit. The error should be more immediately reported.
msg189518 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-05-18 14:41
The problem is that element_setattro is returning a wrong value for error - NULL instead of -1. So the exception is set and is triggered on the next line instead. Will fix for 3.3 and default branches
msg189520 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-05-18 14:53
New changeset 9682241dc8fc by Eli Bendersky in branch '3.3': Issue #17989: element_setattro returned incorrect error value. http://hg.python.org/cpython/rev/9682241dc8fc New changeset b111ae4f83ef by Eli Bendersky in branch 'default': Issue #17989: element_setattro returned incorrect error value. http://hg.python.org/cpython/rev/b111ae4f83ef
msg189521 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-05-18 14:54
Fixed. Thanks for the report! Python 3.4.0a0 (default:1b760f926846+9682241dc8fc+, May 18 2013, 07:52:49) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import xml.etree.ElementTree as ET; j = ET.Element('j') >>> j.ham = 2 Traceback (most recent call last): File "", line 1, in AttributeError: Can't set arbitraty attributes on Element >>>
msg189625 - (view) Author: Joe Stuart (jjstuart) Date: 2013-05-19 21:39
Looks like a typo in arbitrary. AttributeError: Can't set arbitraty attributes on Element
msg189628 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-05-20 00:00
New changeset 65680e3a7f07 by Eli Bendersky in branch '3.3': Issue #17989: fix typo in error message http://hg.python.org/cpython/rev/65680e3a7f07 New changeset 19767536ce84 by Eli Bendersky in branch 'default': Issue #17989: fix typo in error message http://hg.python.org/cpython/rev/19767536ce84
History
Date User Action Args
2022-04-11 14:57:45 admin set github: 62189
2013-05-20 00:01:03 eli.bendersky set status: open -> closedresolution: fixedstage: resolved
2013-05-20 00:00:40 python-dev set messages: +
2013-05-19 22:07:10 Arfrever set status: closed -> openresolution: fixed -> (no value)stage: resolved -> (no value)
2013-05-19 21:39:02 jjstuart set messages: +
2013-05-18 14:54:53 eli.bendersky set status: open -> closedresolution: fixedstage: needs patch -> resolved
2013-05-18 14:54:41 eli.bendersky set messages: +
2013-05-18 14:53:52 python-dev set nosy: + python-devmessages: +
2013-05-18 14:42:22 eli.bendersky set type: behaviorstage: needs patch
2013-05-18 14:41:56 eli.bendersky set messages: +
2013-05-18 14:14:19 eli.bendersky set messages: +
2013-05-18 14:06:54 eli.bendersky set assignee: eli.bendersky
2013-05-18 07:17:42 Arfrever set files: - ElementTree.patch
2013-05-18 07:15:53 Arfrever set messages: +
2013-05-17 19:11:02 jjstuart set files: + ElementTree.patchmessages: +
2013-05-17 19:02:32 jjstuart set files: - ElementTree.patch
2013-05-17 18:19:31 jjstuart set files: + ElementTree.patchmessages: +
2013-05-17 18:17:16 jjstuart set files: - ElementTree.patch
2013-05-17 18:04:28 jjstuart set files: + ElementTree.patchkeywords: + patchmessages: +
2013-05-17 15:55:53 jjstuart set nosy: + jjstuartmessages: +
2013-05-16 13:57:57 Arfrever set nosy: + Arfreverversions: + Python 3.4
2013-05-16 13:04:44 pitrou set nosy: + eli.bendersky
2013-05-15 22:46:51 jwilk create