Convert the Result's expression context to a statement This is useful when we want to use the stored expression in a statement context (for instance in a code branch). We drop ast.Names if they are appended to statements, as they can't have any side effect. "Bare" n
(self)
| 221 | ) |
| 222 | |
| 223 | def expr_as_stmt(self): |
| 224 | """Convert the Result's expression context to a statement |
| 225 | |
| 226 | This is useful when we want to use the stored expression in a |
| 227 | statement context (for instance in a code branch). |
| 228 | |
| 229 | We drop ast.Names if they are appended to statements, as they |
| 230 | can't have any side effect. "Bare" names still get converted to |
| 231 | statements. |
| 232 | |
| 233 | If there is no expression context, return an empty result. |
| 234 | """ |
| 235 | if self.expr and not (isinstance(self.expr, ast.Name) and self.stmts): |
| 236 | return Result() + asty.Expr(self.expr, value=self.expr) |
| 237 | return Result() |
| 238 | |
| 239 | def rename(self, compiler, new_name): |
| 240 | """Rename the Result's temporary variables to a `new_name`. |
no test coverage detected