diff options
author | Inada Naoki <songofacandy@gmail.com> | 2023-07-15 10:33:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-15 10:33:32 (GMT) |
commit | 2566b74b26bcce24199427acea392aed644f4b17 (patch) | |
tree | 91d2ae486db81b01c8451f26382f2eedddaf2ba1 /Lib/inspect.py | |
parent | bbf62979851283b601b2dac0073ab331ebeb3be9 (diff) | |
download | cpython-2566b74b26bcce24199427acea392aed644f4b17.zip cpython-2566b74b26bcce24199427acea392aed644f4b17.tar.gz cpython-2566b74b26bcce24199427acea392aed644f4b17.tar.bz2 |
gh-81283: compiler: remove indent from docstring (#106411)
Co-authored-by: Éric <merwok@netwok.org>
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index a550202..15f94a1 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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.""" |