Home | History | Annotate | Download | only in pyct

Lines Matching refs:node

49   def visit_Expr(self, node):
50 if (isinstance(node.value, gast.Name) and
51 node.value.id in self.replacements):
52 return self.visit(node.value)
53 self.generic_visit(node)
54 return node
56 def visit_FunctionDef(self, node):
57 node = self.generic_visit(node)
58 if node.name in self.replacements:
59 repl = self.replacements[node.name]
62 'A function name can only be replaced by a Name node. Found: %s' %
64 node.name = repl.id
65 return node
67 def _set_inner_child_context(self, node, ctx):
68 if isinstance(node, gast.Attribute):
69 self._set_inner_child_context(node.value, ctx)
70 node.ctx = gast.Load()
71 elif isinstance(node, gast.Tuple):
72 for e in node.elts:
74 node.ctx = ctx
75 elif isinstance(node, gast.Name):
76 node.ctx = ctx
77 elif isinstance(node, (gast.Str, gast.Num)):
80 raise ValueError('unexpected node type "%s"' % node)
82 def visit_Name(self, node):
83 if node.id not in self.replacements:
84 return node
86 new_nodes = ast_util.copy_clean(self.replacements[node.id])
94 self._set_inner_child_context(e, node.ctx)
96 # For attributes, the inner Name node receives the context, while the
98 self._set_inner_child_context(n, node.ctx)
100 n.ctx = node.ctx
111 # Note: the node will receive the ctx value from the template, see
139 An AST node or list of AST nodes with the replacements made. If the
141 node, the same node will be returned. If the template was a string, an
142 AST node will be returned (a `Module` node in the case of a multi-line
143 string, an `Expr` node otherwise).