summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-10-02 01:24:55 (GMT)
committerGitHub <noreply@github.com>2022-10-02 01:24:55 (GMT)
commita4fbb949659b86b0925b20a9ef6bc2877f397252 (patch)
tree0cd23d85e8ea2a1d02edc72b7e364c758f1c945a /Lib
parent748b2b780dd710139fc78dd795563e917b7e8a9e (diff)
downloadcpython-a4fbb949659b86b0925b20a9ef6bc2877f397252.zip
cpython-a4fbb949659b86b0925b20a9ef6bc2877f397252.tar.gz
cpython-a4fbb949659b86b0925b20a9ef6bc2877f397252.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')
-rw-r--r--Lib/ast.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index d63cb2f..6f235c2 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')