Example #1
0
 def visit_arguments(self, node, parent):
     """visit a Arguments node by returning a fresh instance of it"""
     newnode = new.Arguments()
     _lineno_parent(node, newnode, parent)
     self.asscontext = "Ass"
     newnode.args = [self.visit(child, newnode) for child in node.args]
     self.asscontext = None
     newnode.defaults = [self.visit(child, newnode) for child in node.defaults]
     newnode.vararg = node.vararg
     newnode.kwarg = node.kwarg
     self._save_argument_name(newnode)
     newnode.set_line_info(newnode.last_child())
     return newnode
Example #2
0
def build_function(name, args=None, defaults=None, flag=0, doc=None):
    """create and initialize a astng Function node"""
    args, defaults = args or [], defaults or []
    # first argument is now a list of decorators
    func = nodes.Function(name, doc)
    func.args = argsnode = nodes.Arguments()
    argsnode.args = []
    for arg in args:
        argsnode.args.append(nodes.Name())
        argsnode.args[-1].name = arg
        argsnode.args[-1].parent = argsnode
    argsnode.defaults = []
    for default in defaults:
        argsnode.defaults.append(nodes.const_factory(default))
        argsnode.defaults[-1].parent = argsnode
    argsnode.kwarg = None
    argsnode.vararg = None
    argsnode.parent = func
    if args:
        register_arguments(func)
    return func
Example #3
0
 def visit_arguments(self, node, parent):
     """visit an Arguments node by returning a fresh instance of it"""
     # /!\ incoming node is Function or Lambda, coming directly from visit_*
     if node.flags & 8:
         kwarg = node.argnames.pop()
     else:
         kwarg = None
     if node.flags & 4:
         vararg = node.argnames.pop()
     else:
         vararg = None
     newnode = new.Arguments(vararg, kwarg)
     newnode.parent = parent
     newnode.fromlineno = parent.fromlineno
     try:
         newnode.tolineno = parent.blockstart_tolineno
     except AttributeError:  # lambda
         newnode.tolineno = parent.tolineno
     newnode.args = self._nodify_args(newnode, node.argnames)
     self._save_argument_name(newnode)
     newnode.defaults = [self.visit(n, newnode) for n in node.defaults]
     return newnode