Skip to content

Commit 2f07a66

Browse files
committed
Issue #24688: ast.get_docstring() for 'async def' functions.
1 parent 943ddac commit 2f07a66

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def get_docstring(node, clean=True):
194194
be found. If the node provided does not have docstrings a TypeError
195195
will be raised.
196196
"""
197-
if not isinstance(node, (FunctionDef, ClassDef, Module)):
197+
if not isinstance(node, (AsyncFunctionDef, FunctionDef, ClassDef, Module)):
198198
raise TypeError("%r can't have docstrings" % node.__class__.__name__)
199199
if node.body and isinstance(node.body[0], Expr) and \
200200
isinstance(node.body[0].value, Str):

Lib/test/test_ast.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ def test_get_docstring(self):
511511
self.assertEqual(ast.get_docstring(node.body[0]),
512512
'line one\nline two')
513513

514+
node = ast.parse('async def foo():\n """spam\n ham"""')
515+
self.assertEqual(ast.get_docstring(node.body[0]), 'spam\nham')
516+
514517
def test_literal_eval(self):
515518
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
516519
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Library
5353
- Issue #24669: Fix inspect.getsource() for 'async def' functions.
5454
Patch by Kai Groner.
5555

56+
- Issue #24688: ast.get_docstring() for 'async def' functions.
57+
5658
Build
5759
-----
5860

0 commit comments

Comments
 (0)