[issue13536] ast.literal_eval fails on sets

Nick Coghlan report at bugs.python.org
Tue Dec 6 02:29:20 CET 2011


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Dict and Set comprehensions are also broken:

>>> {1 for x in ()}
set([])
>>> {1:2 for x in ()}
{}
>>> ast.literal_eval("{1 for x in ()}")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/ast.py", line 80, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib64/python2.7/ast.py", line 79, in _convert
    raise ValueError('malformed string')
ValueError: malformed string
>>> ast.literal_eval("{1:2 for x in ()}")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/ast.py", line 80, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib64/python2.7/ast.py", line 79, in _convert
    raise ValueError('malformed string')
ValueError: malformed string

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13536>
_______________________________________


More information about the Python-bugs-list mailing list