Apply the AST transformations from self.ast_transformers Parameters ---------- node : ast.Node The root node to be transformed. Typically called with the ast.Module produced by parsing user input. Returns ------- An ast.Node c
(self, node)
| 3553 | return cell |
| 3554 | |
| 3555 | def transform_ast(self, node): |
| 3556 | """Apply the AST transformations from self.ast_transformers |
| 3557 | |
| 3558 | Parameters |
| 3559 | ---------- |
| 3560 | node : ast.Node |
| 3561 | The root node to be transformed. Typically called with the ast.Module |
| 3562 | produced by parsing user input. |
| 3563 | |
| 3564 | Returns |
| 3565 | ------- |
| 3566 | An ast.Node corresponding to the node it was called with. Note that it |
| 3567 | may also modify the passed object, so don't rely on references to the |
| 3568 | original AST. |
| 3569 | """ |
| 3570 | for transformer in self.ast_transformers: |
| 3571 | try: |
| 3572 | node = transformer.visit(node) |
| 3573 | except InputRejected: |
| 3574 | # User-supplied AST transformers can reject an input by raising |
| 3575 | # an InputRejected. Short-circuit in this case so that we |
| 3576 | # don't unregister the transform. |
| 3577 | raise |
| 3578 | except Exception as e: |
| 3579 | warn( |
| 3580 | "AST transformer %r threw an error. It will be unregistered. %s" |
| 3581 | % (transformer, e) |
| 3582 | ) |
| 3583 | self.ast_transformers.remove(transformer) |
| 3584 | |
| 3585 | if self.ast_transformers: |
| 3586 | ast.fix_missing_locations(node) |
| 3587 | return node |
| 3588 | |
| 3589 | async def run_ast_nodes( |
| 3590 | self, |
no test coverage detected