]> granicus.if.org Git - python/commitdiff
Issue #24688: ast.get_docstring() for 'async def' functions.
authorYury Selivanov <yselivanov@sprymix.com>
Thu, 23 Jul 2015 05:54:35 +0000 (08:54 +0300)
committerYury Selivanov <yselivanov@sprymix.com>
Thu, 23 Jul 2015 05:54:35 +0000 (08:54 +0300)
Lib/ast.py
Lib/test/test_ast.py
Misc/NEWS

index 02c3b2867fa85546d96c9a873d0428930b323e08..03c30f66e915093b16fcb6121eb1825b48abdc81 100644 (file)
@@ -194,7 +194,7 @@ def get_docstring(node, clean=True):
     be found.  If the node provided does not have docstrings a TypeError
     will be raised.
     """
-    if not isinstance(node, (FunctionDef, ClassDef, Module)):
+    if not isinstance(node, (AsyncFunctionDef, FunctionDef, ClassDef, Module)):
         raise TypeError("%r can't have docstrings" % node.__class__.__name__)
     if node.body and isinstance(node.body[0], Expr) and \
        isinstance(node.body[0].value, Str):
index c220a3cac2c662959b68be41592c730f45f42c43..7ed03e70e0bb29ba197a6a43f9b7d389f2158af3 100644 (file)
@@ -511,6 +511,9 @@ class ASTHelpers_Test(unittest.TestCase):
         self.assertEqual(ast.get_docstring(node.body[0]),
                          'line one\nline two')
 
+        node = ast.parse('async def foo():\n  """spam\n  ham"""')
+        self.assertEqual(ast.get_docstring(node.body[0]), 'spam\nham')
+
     def test_literal_eval(self):
         self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
         self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
index 4e43e773b5c5b6e317b619026b2ad6d4ce9d981a..bbd8e92d65548b10ccc6c1f5c92aed17498fe06d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -53,6 +53,8 @@ Library
 - Issue #24669: Fix inspect.getsource() for 'async def' functions.
   Patch by Kai Groner.
 
+- Issue #24688: ast.get_docstring() for 'async def' functions.
+
 Build
 -----