summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorAlex Hall <alex.mojaki@gmail.com>2019-10-18 19:34:37 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-10-18 19:34:37 +0200
commit9d2d6ee0988ff009fd6dee9a02958588a8994cfe (patch)
treefbbdfb7bbfb935591cb0fcab85c8f5b45550a801 /astroid
parent8cb02857852d6c1b024d322e54288e57b56359e3 (diff)
downloadastroid-git-9d2d6ee0988ff009fd6dee9a02958588a8994cfe.tar.gz
Fix async function definitions with decorators (#710)
Diffstat (limited to 'astroid')
-rw-r--r--astroid/as_string.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/astroid/as_string.py b/astroid/as_string.py
index 222b6199..a19400ed 100644
--- a/astroid/as_string.py
+++ b/astroid/as_string.py
@@ -300,17 +300,18 @@ class AsStringVisitor:
_import_string(node.names),
)
- def visit_functiondef(self, node):
- """return an astroid.Function node as string"""
+ def handle_functiondef(self, node, keyword):
+ """return a (possibly async) function definition node as string"""
decorate = node.decorators.accept(self) if node.decorators else ""
docs = self._docs_dedent(node.doc) if node.doc else ""
trailer = ":"
if node.returns:
return_annotation = " -> " + node.returns.as_string()
trailer = return_annotation + ":"
- def_format = "\n%sdef %s(%s)%s%s\n%s"
+ def_format = "\n%s%s %s(%s)%s%s\n%s"
return def_format % (
decorate,
+ keyword,
node.name,
node.args.accept(self),
trailer,
@@ -318,6 +319,14 @@ class AsStringVisitor:
self._stmt_list(node.body),
)
+ def visit_functiondef(self, node):
+ """return an astroid.FunctionDef node as string"""
+ return self.handle_functiondef(node, "def")
+
+ def visit_asyncfunctiondef(self, node):
+ """return an astroid.AsyncFunction node as string"""
+ return self.handle_functiondef(node, "async def")
+
def visit_generatorexp(self, node):
"""return an astroid.GeneratorExp node as string"""
return "(%s %s)" % (
@@ -573,10 +582,6 @@ class AsStringVisitor3(AsStringVisitor):
return "(%s)" % (expr,)
- def visit_asyncfunctiondef(self, node):
- function = super(AsStringVisitor3, self).visit_functiondef(node)
- return "async " + function.strip()
-
def visit_await(self, node):
return "await %s" % node.value.accept(self)