summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-10-02 01:21:15 (GMT)
committerGitHub <noreply@github.com>2022-10-02 01:21:15 (GMT)
commit9189cd6b05a32b67981d2157947d745b2d0dac88 (patch)
tree1757be15bc9d1f19a1f249fb68eb37f1ae377f5b /Lib/ast.py
parent35a394c556d04048f24deda879b8547c598928dc (diff)
downloadcpython-9189cd6b05a32b67981d2157947d745b2d0dac88.zip
cpython-9189cd6b05a32b67981d2157947d745b2d0dac88.tar.gz
cpython-9189cd6b05a32b67981d2157947d745b2d0dac88.tar.bz2
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 8baef8ae367041a5cfefb40b19c7b87e9bcb56a2) Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index b0e1c41..8c10d08 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -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')