mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
bpo-29637: clean docstring only if not None (GH-267)
This commit is contained in:
parent
357bad7101
commit
41cea70aa3
2 changed files with 5 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue