MCPcopy Index your code
hub / github.com/ipython/ipython / visit_Module

Method visit_Module

IPython/core/magics/ast_mod.py:287–314  ·  view source on GitHub ↗
(self, code)

Source from the content-addressed store, hash-verified

285 )
286
287 def visit_Module(self, code):
288 if not self.enabled:
289 return code
290 # if not isinstance(code, ast.Module):
291 # recursively called...
292 # return generic_visit(self, code)
293 last = code.body[-1]
294 if isinstance(last, Expr):
295 code.body.pop()
296 code.body.append(Assign([Name("ret-tmp", ctx=Store())], value=last.value))
297 ast.fix_missing_locations(code)
298 ret = Expr(value=Name("ret-tmp", ctx=Load()))
299 ret = ast.fix_missing_locations(ret)
300 self.mapping["__ret__"] = ret
301 else:
302 self.mapping["__ret__"] = ast.parse("None").body[0]
303 self.mapping["__code__"] = code.body
304 tpl = ast.fix_missing_locations(self.template)
305
306 tx = copy.deepcopy(tpl)
307 tx = self.mangler.visit(tx)
308 node = self.generic_visit(tx)
309 node_2 = ast.fix_missing_locations(node)
310 if self.debug:
311 print("---- Transformed code ----")
312 print(ast.unparse(node_2))
313 print("---- ---------------- ----")
314 return node_2
315
316 # this does not work as the name might be in a list and one might want to extend the list.
317 # def visit_Name(self, name):

Callers

nothing calls this directly

Calls 3

popMethod · 0.80
visitMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected