[issue24146] ast.literal_eval doesn't support the Python ternary operator
Serhiy Storchaka
report at bugs.python.org
Fri May 8 16:16:11 CEST 2015
Serhiy Storchaka added the comment:
No it doesn't support all Python operators.
>>> ast.literal_eval('2*3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/ast.py", line 84, in literal_eval
return _convert(node_or_string)
File "/usr/lib/python3.4/ast.py", line 83, in _convert
raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.BinOp object at 0xb6f8446c>
And shouldn't. It supports "+" and "-" only because they are needed for support of complex "literals". It is unintentional side effect, that ast.literal_eval() supports not only "2+3j", but "2+3" too.
----------
nosy: +mark.dickinson, serhiy.storchaka
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24146>
_______________________________________
More information about the Python-bugs-list
mailing list