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

Function eval_ast_expr

Tools/clinic/libclinic/dsl_parser.py:148–169  ·  view source on GitHub ↗

Takes an ast.Expr node. Compiles it into a function object, then calls the function object with 0 arguments. Returns the result of that function call. globals represents the globals dict the expression should see. (There's no equivalent for "locals" here.)

(
    node: ast.expr,
    *,
    filename: str = '-'
)

Source from the content-addressed store, hash-verified

146
147
148def eval_ast_expr(
149 node: ast.expr,
150 *,
151 filename: str = '-'
152) -> Any:
153 """
154 Takes an ast.Expr node. Compiles it into a function object,
155 then calls the function object with 0 arguments.
156 Returns the result of that function call.
157
158 globals represents the globals dict the expression
159 should see. (There's no equivalent for "locals" here.)
160 """
161
162 if isinstance(node, ast.Expr):
163 node = node.value
164
165 expr = ast.Expression(node)
166 namespace = create_parser_namespace()
167 co = compile(expr, filename, 'eval')
168 fn = FunctionType(co, namespace)
169 return fn()
170
171
172class IndentStack:

Callers 1

parse_converterMethod · 0.85

Calls 3

create_parser_namespaceFunction · 0.90
fnFunction · 0.85
compileFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…