changeset: 97012:ecb13b9c4cd0 branch: 3.5 parent: 97010:9474ae243afa user: Yury Selivanov date: Thu Jul 23 08:54:35 2015 +0300 files: Lib/ast.py Lib/test/test_ast.py Misc/NEWS description: Issue #24688: ast.get_docstring() for 'async def' functions. diff -r 9474ae243afa -r ecb13b9c4cd0 Lib/ast.py --- a/Lib/ast.py Thu Jul 23 08:08:59 2015 +1200 +++ b/Lib/ast.py Thu Jul 23 08:54:35 2015 +0300 @@ -194,7 +194,7 @@ 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): diff -r 9474ae243afa -r ecb13b9c4cd0 Lib/test/test_ast.py --- a/Lib/test/test_ast.py Thu Jul 23 08:08:59 2015 +1200 +++ b/Lib/test/test_ast.py Thu Jul 23 08:54:35 2015 +0300 @@ -511,6 +511,9 @@ 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}) diff -r 9474ae243afa -r ecb13b9c4cd0 Misc/NEWS --- a/Misc/NEWS Thu Jul 23 08:08:59 2015 +1200 +++ b/Misc/NEWS Thu Jul 23 08:54:35 2015 +0300 @@ -53,6 +53,8 @@ - Issue #24669: Fix inspect.getsource() for 'async def' functions. Patch by Kai Groner. +- Issue #24688: ast.get_docstring() for 'async def' functions. + Build -----