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 = '-'
)
| 146 | |
| 147 | |
| 148 | def 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 | |
| 172 | class IndentStack: |
no test coverage detected
searching dependent graphs…