@@ -144,11 +144,21 @@ def clean_url_string(url: str) -> str:
144
144
return url
145
145
146
146
147
- def get_docstring (obj : Any , remove_newlines = True ) -> str :
147
+ def get_docstring (obj : Any , remove_newlines = True , remove_summary = False ) -> str :
148
148
"""Return the docstring of an object
149
149
150
+ If `remove_newlines` is `True` (default), newlines are removed from the string.
151
+ If `remove_summary` is `True` (not default), and the docstring's second line
152
+ is blank, the first two lines are removed. If the docstring follows the
153
+ convention of a one-line summary, a blank line, and a description, this will
154
+ get just the description.
155
+
156
+ If `remove_newlines` is `False`, the docstring is processed by
157
+ `inspect.cleandoc()` to remove whitespace from the start of each line.
158
+
150
159
:param obj: Any Python object
151
160
:param remove_newlines: bool (Default value = True)
161
+ :param remove_summary: bool (Default value = False)
152
162
:returns: str: Object docstring
153
163
154
164
"""
@@ -158,6 +168,10 @@ def get_docstring(obj: Any, remove_newlines=True) -> str:
158
168
if remove_newlines :
159
169
stripped = [line .strip () for line in ds .splitlines () if line ]
160
170
return " " .join (stripped ).replace ("\n " , " " ).replace ("\r " , "" )
171
+ if remove_summary :
172
+ lines = ds .splitlines ()
173
+ if len (lines ) > 2 and lines [1 ].strip () == "" :
174
+ ds = "\n " .join (lines [2 :])
161
175
return inspect .cleandoc (ds ) # Strip spurious indentation/newlines
162
176
163
177
0 commit comments