[docs] [issue22525] ast.literal_eval() doesn't do what the documentation says

Georg Brandl report at bugs.python.org
Tue Sep 30 19:29:54 CEST 2014


Georg Brandl added the comment:

I agree that the wording can be improved.  The term "expression" is used here loosely, but should be clarified.

"a+b" with numbers a, b must be handled in order to evaluate complex literals as in "1+1j".

Allowing operator expressions with literals is possible, but much more complex than the current implementation.  A simple implementation is not safe: you can induce basically unbounded CPU and memory usage with no effort (try "9**9**9" or "[None] * 9**9").

As for the usefulness, this function is useful to "read back" literal values and containers as stringified by repr().  This can for example be used for serialization in a format that is similar to but more powerful than JSON.

----------
nosy: +georg.brandl

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


More information about the docs mailing list