Factor out docstring dedenting from inspect.getdoc() into inspect.cleandoc()
to ease standalone use of the algorithm.
diff --git a/Lib/inspect.py b/Lib/inspect.py
index b492514..ad94ad1 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -368,6 +368,13 @@
return None
if not isinstance(doc, types.StringTypes):
return None
+ return cleandoc(doc)
+
+def cleandoc(doc):
+ """Clean up indentation from docstrings.
+
+ Any whitespace that can be uniformly removed from the second line
+ onwards is removed."""
try:
lines = string.split(string.expandtabs(doc), '\n')
except UnicodeError: