[issue39538] SystemError when set Element.attrib to non-dict

2020-03-22 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Fixed by issue39822. e.attrib = 1 now raises a TypeError.

--
resolution:  -> out of date
stage: needs patch -> resolved
status: open -> closed
versions:  -Python 2.7, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39538] SystemError when set Element.attrib to non-dict

2020-02-05 Thread Stefan Behnel

Stefan Behnel  added the comment:

I agree that SystemError is the wrong response. Whether it needs to be 
AttributeError – probably fine to consider this an implementation detail. 
TypeError also seems ok in at least some of the cases. I think we should widen 
the code to expect some kind of Mapping (instead of strictly a dict), and if we 
don't find that on access, a TypeError seems just as good as an AttributeError 
from Python.

I'm unsure if we should restrict assignments to ".attrib". It's probably enough 
to allow "None" assignments to say "no attributes allowed", Everything else can 
be handled by some kind of Mapping object. But then, why not just use the 
Mapping protocol on access and leave errors to that stage?

--
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39538] SystemError when set Element.attrib to non-dict

2020-02-03 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

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 "", line 1, in 
SystemError: Objects/dictobject.c:1438: bad argument to internal function
>>> e.items()
Traceback (most recent call last):
  File "", line 1, in 
SystemError: Objects/dictobject.c:2732: bad argument to internal function
>>> e.keys()
Traceback (most recent call last):
  File "", line 1, in 
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 "", line 1, in 
  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 "", line 1, in 
  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 "", line 1, in 
  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__().

--
components: Extension Modules, XML
messages: 361279
nosy: eli.bendersky, scoder, serhiy.storchaka
priority: normal
severity: normal
status: open
title: SystemError when set Element.attrib to non-dict
type: behavior
versions: Python 2.7, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com