mirror of
https://github.com/python/cpython.git
synced 2025-08-18 07:41:05 +00:00
gh-95588: Drop the safety claim from ast.literal_eval
docs. (GH-95919)
It was never really safe and this claim conflicts directly with the big warning in the docs about it being able to crash the interpreter.
(cherry picked from commit 8baef8ae36
)
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
parent
748b2b780d
commit
a4fbb94965
3 changed files with 25 additions and 9 deletions
|
@ -53,10 +53,12 @@ def parse(source, filename='<unknown>', mode='exec', *,
|
|||
|
||||
def literal_eval(node_or_string):
|
||||
"""
|
||||
Safely evaluate an expression node or a string containing a Python
|
||||
Evaluate an expression node or a string containing only a Python
|
||||
expression. The string or node provided may only consist of the following
|
||||
Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
|
||||
sets, booleans, and None.
|
||||
|
||||
Caution: A complex expression can overflow the C stack and cause a crash.
|
||||
"""
|
||||
if isinstance(node_or_string, str):
|
||||
node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue