Skip to content

Commit

Permalink
Issue #24688: ast.get_docstring() for 'async def' functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
1st1 committed Jul 23, 2015
1 parent 998ea43 commit efba493
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/ast.py
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_ast.py
Expand Up @@ -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})
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS
Expand Up @@ -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
-----

Expand Down

0 comments on commit efba493

Please sign in to comment.