From efba4936c47d31cce479f2b991cb52363d5621e2 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 23 Jul 2015 08:54:35 +0300 Subject: [PATCH] Issue #24688: ast.get_docstring() for 'async def' functions. --- Lib/ast.py | 2 +- Lib/test/test_ast.py | 3 +++ Misc/NEWS | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/ast.py b/Lib/ast.py index 02c3b2867fa855..03c30f66e91509 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -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): diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index c220a3cac2c662..7ed03e70e0bb29 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -511,6 +511,9 @@ def test_get_docstring(self): 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 --git a/Misc/NEWS b/Misc/NEWS index 4e43e773b5c5b6..bbd8e92d65548b 100644 --- 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 -----