[Python-checkins] cpython (3.5): Issue #24688: ast.get_docstring() for 'async def' functions.
yury.selivanov
python-checkins at python.org
Thu Jul 23 07:55:30 CEST 2015
https://hg.python.org/cpython/rev/ecb13b9c4cd0
changeset: 97012:ecb13b9c4cd0
branch: 3.5
parent: 97010:9474ae243afa
user: Yury Selivanov <yselivanov at sprymix.com>
date: Thu Jul 23 08:54:35 2015 +0300
summary:
Issue #24688: ast.get_docstring() for 'async def' functions.
files:
Lib/ast.py | 2 +-
Lib/test/test_ast.py | 3 +++
Misc/NEWS | 2 ++
3 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/Lib/ast.py b/Lib/ast.py
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -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 --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -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 --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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
-----
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list