diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-07-23 05:54:35 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-07-23 05:54:35 (GMT) |
commit | 2f07a66dedb6f69cbe601f7ca2c3fca66898ffe3 (patch) | |
tree | 6c8fc0a96b616e02eab21f54afc4ba3dc6741235 | |
parent | 943ddac14227bf9cdd224903bc5f5696997a0129 (diff) | |
download | cpython-2f07a66dedb6f69cbe601f7ca2c3fca66898ffe3.zip cpython-2f07a66dedb6f69cbe601f7ca2c3fca66898ffe3.tar.gz cpython-2f07a66dedb6f69cbe601f7ca2c3fca66898ffe3.tar.bz2 |
Issue #24688: ast.get_docstring() for 'async def' functions.
-rw-r--r-- | Lib/ast.py | 2 | ||||
-rw-r--r-- | Lib/test/test_ast.py | 3 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
3 files changed, 6 insertions, 1 deletions
@@ -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 c220a3c..7ed03e7 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -511,6 +511,9 @@ class ASTHelpers_Test(unittest.TestCase): 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}) @@ -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 ----- |