Visitar URL original
gh-104050: Annotate toplevel functions in clinic.py by erlend-aasland · Pull Request #106435 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Annotate eval_ast_expr()
  • Loading branch information
erlend-aasland committed Jul 4, 2023
commit 77ef6938abf5e5d65019a09c9f3e741fdb85588e
11 changes: 8 additions & 3 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4219,7 +4219,12 @@ class float_return_converter(double_return_converter):
cast = '(double)'


def eval_ast_expr(node, globals, *, filename='-'):
def eval_ast_expr(
node: ast.expr,
globals: dict[str, Any],
*,
filename: str = '-'
) -> FunctionType:
"""
Takes an ast.Expr node. Compiles and evaluates it.
Returns the result of the expression.
Expand All @@ -4231,8 +4236,8 @@ def eval_ast_expr(node, globals, *, filename='-'):
if isinstance(node, ast.Expr):
node = node.value

node = ast.Expression(node)
co = compile(node, filename, 'eval')
expr = ast.Expression(node)
co = compile(expr, filename, 'eval')
fn = FunctionType(co, globals)
return fn()

Expand Down