Skip to content

Commit 0dc8e57

Browse files
committed
Implement trim_docstring
Thin wrapper around `inspect.clean_doc`
1 parent d1d8722 commit 0dc8e57

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from ..trim_docstring import trim_docstring
2+
3+
4+
def test_trim_docstring():
5+
class WellDocumentedObject(object):
6+
"""
7+
This object is very well-documented. It has multiple lines in its
8+
description.
9+
10+
Multiple paragraphs too
11+
"""
12+
pass
13+
14+
assert (trim_docstring(WellDocumentedObject.__doc__) ==
15+
"This object is very well-documented. It has multiple lines in its\n"
16+
"description.\n\nMultiple paragraphs too")
17+
18+
class UndocumentedObject(object):
19+
pass
20+
21+
assert trim_docstring(UndocumentedObject.__doc__) is None

graphene/utils/trim_docstring.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import inspect
2+
3+
4+
def trim_docstring(docstring):
5+
# Cleans up whitespaces from an indented docstring
6+
#
7+
# See https://www.python.org/dev/peps/pep-0257/
8+
# and https://docs.python.org/2/library/inspect.html#inspect.cleandoc
9+
return inspect.cleandoc(docstring) if docstring else None

0 commit comments

Comments
 (0)