def visit_Call(self, node):
if not self.config.inlining:
return
# FIXME: renaming variables to avoid clashes
# or do something like:
# .saved_locals = locals()
# set params to args
# body of called function
# locals() = .saved_locals
# how to things that aren't just a return
# how to handle early return
# FIXME: what guards are needed?
# etc
expansion = self.can_inline(node)
if not expansion:
return node
funcdef = expansion.funcdef
# Substitute the Call with the expression of the single return stmt
# within the callee.
# This assumes a single Return or Pass stmt
stmt = funcdef.body[0]
if isinstance(stmt, ast.Return):
returned_expr = funcdef.body[0].value
# Rename params/args
v = RenameVisitor(node, funcdef, expansion.actual_pos_args)
new_expr = v.visit(returned_expr)
else:
assert isinstance(stmt, ast.Pass)
new_expr = self.new_constant(stmt, None)
return new_expr
评论列表
文章目录