New submission from Saiyang Gou <[email protected]>:
`ast.literal_eval` does not accept code with leading whitespaces, while `eval`
accepts them, which is an inconsistency.
```
>>> import ast
>>> eval(' 1')
1
>>> ast.literal_eval(' 1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/ast.py", line 62, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
File "/usr/local/lib/python3.9/ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 1
1
IndentationError: unexpected indent
```
----------
components: Library (Lib)
messages: 377687
nosy: gousaiyang
priority: normal
severity: normal
status: open
title: ast.literal_eval does not accept strings with leading whitespaces
type: enhancement
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41887>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com