Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_enter_call_nodes(self):
for node in self.nodes:
if isinstance(node, (ast.Module, ast.FunctionDef)):
for stmt in node.body:
if not is_future_import(stmt):
stmt._enter_call_node = True
break
def set_basic_node_attributes(self):
self.nodes = [] # type: List[ast.AST]
for node in ast.walk(self.root): # type: ast.AST
for child in ast.iter_child_nodes(node):
child.parent = node
node._tree_index = len(self.nodes)
self.nodes.append(node)
# Mark __future__ imports and anything before (i.e. module docstrings)
# to be ignored by the AST transformer
for i, stmt in enumerate(self.root.body):
if is_future_import(stmt):
for s in self.root.body[:i + 1]:
for node in ast.walk(s):
node._visit_ignore = True
def exec_ipython_cell(self, source, callback):
from IPython import get_ipython
shell = get_ipython()
filename = name = shell.compile.cache(source)
flags = shell.compile.flags
traced_file = self.compile(source, filename, flags)
traced_file.is_ipython_cell = True
for node in traced_file.root.body:
if is_future_import(node):
raise ValueError('from __future__ import ... statements '
'are not allowed in cells traced with %%eye')
shell.user_global_ns.update(self._trace_methods_dict(traced_file))
self._trace(name, filename, traced_file, traced_file.code, 'module', source)
try:
shell.ex(traced_file.code)
return self._ipython_cell_value
finally:
callback(self._last_call_id)
self._ipython_cell_value = None
def exec_ipython_cell(self, source, callback):
from IPython import get_ipython
shell = get_ipython()
filename = name = shell.compile.cache(source)
flags = shell.compile.flags
traced_file = self.compile(source, filename, flags)
traced_file.is_ipython_cell = True
for node in traced_file.root.body:
if is_future_import(node):
raise ValueError('from __future__ import ... statements '
'are not allowed in cells traced with %%eye')
shell.user_global_ns.update(self._trace_methods_dict(traced_file))
self._trace(name, filename, traced_file, traced_file.code, 'module', source)
try:
shell.ex(traced_file.code)
return self._ipython_cell_value
finally:
callback(self._last_call_id)
self._ipython_cell_value = None
def set_enter_call_nodes(self):
for node in self.nodes:
if isinstance(node, (ast.Module, ast.FunctionDef)):
for stmt in node.body:
if not is_future_import(stmt):
stmt._enter_call_node = True
break
def set_basic_node_attributes(self):
self.nodes = [] # type: List[ast.AST]
for node in ast.walk(self.root): # type: ast.AST
for child in ast.iter_child_nodes(node):
child.parent = node
node._tree_index = len(self.nodes)
self.nodes.append(node)
# Mark __future__ imports and anything before (i.e. module docstrings)
# to be ignored by the AST transformer
for i, stmt in enumerate(self.root.body):
if is_future_import(stmt):
for s in self.root.body[:i + 1]:
for node in ast.walk(s):
node._visit_ignore = True