MCPcopy
hub / github.com/hylang/hy / expr_as_stmt

Method expr_as_stmt

hy/compiler.py:223–237  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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`.

Callers 10

compile_while_expressionFunction · 0.95
compile_requireFunction · 0.95
_compile_branchMethod · 0.80
hy_compileFunction · 0.80
compile_comprehensionFunction · 0.80
fFunction · 0.80
compile_match_expressionFunction · 0.80
compile_try_expressionFunction · 0.80
compile_macro_defFunction · 0.80
compile_class_expressionFunction · 0.80

Calls 1

ResultClass · 0.85

Tested by

no test coverage detected