MCPcopy Index your code
hub / github.com/python/cpython / literal_eval

Function literal_eval

Lib/ast.py:51–64  ·  view source on GitHub ↗

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 over

(node_or_string)

Source from the content-addressed store, hash-verified

49
50
51def literal_eval(node_or_string):
52 """
53 Evaluate an expression node or a string containing only a Python
54 expression. The string or node provided may only consist of the following
55 Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
56 sets, booleans, and None.
57
58 Caution: A complex expression can overflow the C stack and cause a crash.
59 """
60 if isinstance(node_or_string, str):
61 node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval').body
62 elif isinstance(node_or_string, Expression):
63 node_or_string = node_or_string.body
64 return _convert_literal(node_or_string)
65
66
67def _convert_literal(node):

Callers 3

test_ssl.pyFile · 0.90
utils.pyFile · 0.90
metaMethod · 0.90

Calls 3

_convert_literalFunction · 0.85
parseFunction · 0.70
lstripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…