gh-95588: Drop the safety claim from `ast.literal_eval` docs. by gpshead · Pull Request #95919 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Doc/library/ast.rst
4 changes: 3 additions & 1 deletion Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,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')
Expand Down