Commit 2f07a66d authored by Yury Selivanov's avatar Yury Selivanov

Issue #24688: ast.get_docstring() for 'async def' functions.

parent 943ddac1
...@@ -194,7 +194,7 @@ def get_docstring(node, clean=True): ...@@ -194,7 +194,7 @@ def get_docstring(node, clean=True):
be found. If the node provided does not have docstrings a TypeError be found. If the node provided does not have docstrings a TypeError
will be raised. 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__) raise TypeError("%r can't have docstrings" % node.__class__.__name__)
if node.body and isinstance(node.body[0], Expr) and \ if node.body and isinstance(node.body[0], Expr) and \
isinstance(node.body[0].value, Str): isinstance(node.body[0].value, Str):
......
...@@ -511,6 +511,9 @@ class ASTHelpers_Test(unittest.TestCase): ...@@ -511,6 +511,9 @@ class ASTHelpers_Test(unittest.TestCase):
self.assertEqual(ast.get_docstring(node.body[0]), self.assertEqual(ast.get_docstring(node.body[0]),
'line one\nline two') '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): def test_literal_eval(self):
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3]) self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42}) self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
......
...@@ -53,6 +53,8 @@ Library ...@@ -53,6 +53,8 @@ Library
- Issue #24669: Fix inspect.getsource() for 'async def' functions. - Issue #24669: Fix inspect.getsource() for 'async def' functions.
Patch by Kai Groner. Patch by Kai Groner.
- Issue #24688: ast.get_docstring() for 'async def' functions.
Build Build
----- -----
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment