mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-81283: compiler: remove indent from docstring (#106411)
Co-authored-by: Éric <merwok@netwok.org>
This commit is contained in:
parent
bbf6297985
commit
2566b74b26
9 changed files with 246 additions and 30 deletions
|
@ -881,29 +881,28 @@ def cleandoc(doc):
|
|||
|
||||
Any whitespace that can be uniformly removed from the second line
|
||||
onwards is removed."""
|
||||
try:
|
||||
lines = doc.expandtabs().split('\n')
|
||||
except UnicodeError:
|
||||
return None
|
||||
else:
|
||||
# Find minimum indentation of any non-blank lines after first line.
|
||||
margin = sys.maxsize
|
||||
for line in lines[1:]:
|
||||
content = len(line.lstrip())
|
||||
if content:
|
||||
indent = len(line) - content
|
||||
margin = min(margin, indent)
|
||||
# Remove indentation.
|
||||
if lines:
|
||||
lines[0] = lines[0].lstrip()
|
||||
if margin < sys.maxsize:
|
||||
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 '\n'.join(lines)
|
||||
lines = doc.expandtabs().split('\n')
|
||||
|
||||
# Find minimum indentation of any non-blank lines after first line.
|
||||
margin = sys.maxsize
|
||||
for line in lines[1:]:
|
||||
content = len(line.lstrip(' '))
|
||||
if content:
|
||||
indent = len(line) - content
|
||||
margin = min(margin, indent)
|
||||
# Remove indentation.
|
||||
if lines:
|
||||
lines[0] = lines[0].lstrip(' ')
|
||||
if margin < sys.maxsize:
|
||||
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 '\n'.join(lines)
|
||||
|
||||
|
||||
def getfile(object):
|
||||
"""Work out which source or compiled file an object was defined in."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue