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.

Author serhiy.storchaka
Recipients eli.bendersky, scoder, serhiy.storchaka
Date 2020-02-03.10:19:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580725155.12.0.53190069949.issue39538@roundup.psfhosted.org>
In-reply-to
Content
The C implementation raises a SystemError after setting Element.attrib to non-dict.

>>> from xml.etree import ElementTree as ET
>>> e = ET.Element('a')
>>> e.attrib = 1
>>> e.get('x')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Objects/dictobject.c:1438: bad argument to internal function
>>> e.items()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Objects/dictobject.c:2732: bad argument to internal function
>>> e.keys()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Objects/dictobject.c:2712: bad argument to internal function

The only valid non-dict value is None (although it is an implementation detail).

>>> e.attrib = None
>>> e.get('x')
>>> e.items()
[]
>>> e.keys()
[]

The Python implementation raises an AttributeError (even for None).

>>> import sys
>>> sys.modules['_elementtree'] = None
>>> from xml.etree import ElementTree as ET
>>> e = ET.Element('a')
>>> e.attrib = 1
>>> e.get('x')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython3.8/Lib/xml/etree/ElementTree.py", line 358, in get
    return self.attrib.get(key, default)
AttributeError: 'int' object has no attribute 'get'
>>> e.items()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython3.8/Lib/xml/etree/ElementTree.py", line 388, in items
    return self.attrib.items()
AttributeError: 'int' object has no attribute 'items'
>>> e.keys()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython3.8/Lib/xml/etree/ElementTree.py", line 377, in keys
    return self.attrib.keys()
AttributeError: 'int' object has no attribute 'keys'

Other way to trigger an error is via __setstate__().
History
Date User Action Args
2020-02-03 10:19:15serhiy.storchakasetrecipients: + serhiy.storchaka, scoder, eli.bendersky
2020-02-03 10:19:15serhiy.storchakasetmessageid: <1580725155.12.0.53190069949.issue39538@roundup.psfhosted.org>
2020-02-03 10:19:15serhiy.storchakalinkissue39538 messages
2020-02-03 10:19:14serhiy.storchakacreate