Issue24146
Created on 2015-05-08 13:22 by larry, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg242760 - (view) | Author: Larry Hastings (larry) * ![]() |
Date: 2015-05-08 13:22 | |
ast.literal_eval() supports all Python operators, yes? No. It doesn't support "if/else", Python's ternary operator. Is there a reason it does not? I think it probably should. |
|||
| msg242765 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2015-05-08 14:16 | |
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.
|
|||
| msg242767 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2015-05-08 14:25 | |
Right, this isn't a bug, it is that literal_eval is intended only to support *literals*, not expressions. See also issue 22525. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:16 | admin | set | github: 68334 |
| 2015-05-08 14:25:28 | r.david.murray | set | status: open -> closed nosy:
+ r.david.murray resolution: not a bug |
| 2015-05-08 14:16:11 | serhiy.storchaka | set | nosy:
+ mark.dickinson, serhiy.storchaka messages: + msg242765 |
| 2015-05-08 13:22:43 | larry | create | |
