예제 #1
0
    def visit_FunctionDef(self, node):
        self._write_py_context(node.lineno + len(node.decorator_list))
        func = self.visit_function_inline(node)
        self.block.bind_var(self.writer, node.name, func.expr)

        # Docstring should be the 1st statement (expression), if exists
        first_expr = node.body[0]
        if isinstance(first_expr, ast.Expr) and isinstance(
                first_expr.value, ast.Str):
            docstring = first_expr.value
            doc_assign = ast.Assign(
                loc=docstring.loc,
                targets=[
                    ast.Attribute(value=ast.Name(id=node.name), attr='__doc__')
                ],
                value=docstring,
            )
            self.visit_Assign(doc_assign)

        while node.decorator_list:
            decorator = node.decorator_list.pop()
            wrapped = ast.Name(id=node.name)
            decorated = ast.Call(func=decorator,
                                 args=[wrapped],
                                 keywords=[],
                                 starargs=None,
                                 kwargs=None)
            target = ast.Assign(targets=[wrapped],
                                value=decorated,
                                loc=node.loc)
            self.visit_Assign(target)
예제 #2
0
 def visit_FunctionDef(self, node):
   self._write_py_context(node.lineno + len(node.decorator_list))
   func = self.expr_visitor.visit_function_inline(node)
   self.block.bind_var(self.writer, node.name, func.expr)
   while node.decorator_list:
     decorator = node.decorator_list.pop()
     wrapped = ast.Name(id=node.name)
     decorated = ast.Call(func=decorator, args=[wrapped], keywords=[],
                          starargs=None, kwargs=None)
     target = ast.Assign(targets=[wrapped], value=decorated, loc=node.loc)
     self.visit_Assign(target)