Skip to content

Commit e32b752

Browse files
[3.12] gh-121671: Increase test coverage of ast.get_docstring (GH-121674) (GH-121690)
(cherry picked from commit 0a26aa5) Co-authored-by: Tomas R <[email protected]>
1 parent e4c8d89 commit e32b752

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Lib/test/test_ast.py

+9
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,12 @@ def test_get_docstring(self):
13661366
node = ast.parse('async def foo():\n """spam\n ham"""')
13671367
self.assertEqual(ast.get_docstring(node.body[0]), 'spam\nham')
13681368

1369+
node = ast.parse('async def foo():\n """spam\n ham"""')
1370+
self.assertEqual(ast.get_docstring(node.body[0], clean=False), 'spam\n ham')
1371+
1372+
node = ast.parse('x')
1373+
self.assertRaises(TypeError, ast.get_docstring, node.body[0])
1374+
13691375
def test_get_docstring_none(self):
13701376
self.assertIsNone(ast.get_docstring(ast.parse('')))
13711377
node = ast.parse('x = "not docstring"')
@@ -1390,6 +1396,9 @@ def test_get_docstring_none(self):
13901396
node = ast.parse('async def foo():\n x = "not docstring"')
13911397
self.assertIsNone(ast.get_docstring(node.body[0]))
13921398

1399+
node = ast.parse('async def foo():\n 42')
1400+
self.assertIsNone(ast.get_docstring(node.body[0]))
1401+
13931402
def test_multi_line_docstring_col_offset_and_lineno_issue16806(self):
13941403
node = ast.parse(
13951404
'"""line one\nline two"""\n\n'

0 commit comments

Comments
 (0)