Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
41cea70a
Commit
41cea70a
authored
Feb 23, 2017
by
Matthias Bussonnier
Committed by
INADA Naoki
Feb 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29637: clean docstring only if not None (GH-267)
parent
357bad71
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
1 deletion
+5
-1
Lib/ast.py
Lib/ast.py
+4
-1
Lib/test/test_ast.py
Lib/test/test_ast.py
+1
-0
No files found.
Lib/ast.py
View file @
41cea70a
...
...
@@ -194,11 +194,14 @@ def get_docstring(node, clean=True):
Return the docstring for the given node or None if no docstring can
be found. If the node provided does not have docstrings a TypeError
will be raised.
If *clean* is `True`, all tabs are expanded to spaces and any whitespace
that can be uniformly removed from the second line onwards is removed.
"""
if
not
isinstance
(
node
,
(
AsyncFunctionDef
,
FunctionDef
,
ClassDef
,
Module
)):
raise
TypeError
(
"%r can't have docstrings"
%
node
.
__class__
.
__name__
)
text
=
node
.
docstring
if
clean
:
if
clean
and
text
:
import
inspect
text
=
inspect
.
cleandoc
(
text
)
return
text
...
...
Lib/test/test_ast.py
View file @
41cea70a
...
...
@@ -532,6 +532,7 @@ class ASTHelpers_Test(unittest.TestCase):
node
=
ast
.
parse
(
'async def foo():
\
n
"""spam
\
n
ham"""'
)
self
.
assertEqual
(
ast
.
get_docstring
(
node
.
body
[
0
]),
'spam
\
n
ham'
)
self
.
assertIsNone
(
ast
.
get_docstring
(
ast
.
parse
(
''
)))
def
test_literal_eval
(
self
):
self
.
assertEqual
(
ast
.
literal_eval
(
'[1, 2, 3]'
),
[
1
,
2
,
3
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment