summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorKa-Ping Yee <ping@zesty.ca>2002-11-30 03:53:15 (GMT)
committerKa-Ping Yee <ping@zesty.ca>2002-11-30 03:53:15 (GMT)
commita59ef7bbe025b05f5db0973ebdf8d973bf639e26 (patch)
tree1ebb4ff2901fd1134c758ed086340e680632e843 /Lib/inspect.py
parent362c7cd07bd32f94e80e5ca954834cfbc1709953 (diff)
downloadcpython-a59ef7bbe025b05f5db0973ebdf8d973bf639e26.zip
cpython-a59ef7bbe025b05f5db0973ebdf8d973bf639e26.tar.gz
cpython-a59ef7bbe025b05f5db0973ebdf8d973bf639e26.tar.bz2
getdoc():
Remove leading whitespace from first line; remove leading and trailing blank lines from docstrings. (Patch 645938 submitted by David Goodger.)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 96677b7..d3fd3ad 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -275,15 +275,23 @@ def getdoc(object):
except UnicodeError:
return None
else:
- margin = None
+ # Find minimum indentation of any non-blank lines after first line.
+ margin = sys.maxint
for line in lines[1:]:
content = len(string.lstrip(line))
- if not content: continue
- indent = len(line) - content
- if margin is None: margin = indent
- else: margin = min(margin, indent)
- if margin is not None:
+ if content:
+ indent = len(line) - content
+ margin = min(margin, indent)
+ # Remove indentation.
+ if lines:
+ lines[0] = lines[0].lstrip()
+ if margin < sys.maxint:
for i in range(1, len(lines)): lines[i] = lines[i][margin:]
+ # Remove any trailing or leading blank lines.
+ while lines and not lines[-1]:
+ lines.pop()
+ while lines and not lines[0]:
+ lines.pop(0)
return string.join(lines, '\n')
def getfile(object):