mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
_parse_example(): Simplified new code to preserve trailing spaces before
final newline. Anything to get rid of "l" as a variable name <0.5 wink>.
This commit is contained in:
parent
2dd2a28802
commit
c50491591d
1 changed files with 8 additions and 12 deletions
|
@ -738,17 +738,13 @@ class DocTestParser:
|
||||||
self._check_prefix(source_lines[1:], ' '*indent + '.', name, lineno)
|
self._check_prefix(source_lines[1:], ' '*indent + '.', name, lineno)
|
||||||
source = '\n'.join([sl[indent+4:] for sl in source_lines])
|
source = '\n'.join([sl[indent+4:] for sl in source_lines])
|
||||||
|
|
||||||
# Divide want into lines; check that it's properly
|
# Divide want into lines; check that it's properly indented; and
|
||||||
# indented; and then strip the indentation.
|
# then strip the indentation. Spaces before the last newline should
|
||||||
|
# be preserved, so plain rstrip() isn't good enough.
|
||||||
want = m.group('want')
|
want = m.group('want')
|
||||||
|
|
||||||
# Strip trailing newline and following spaces
|
|
||||||
l = len(want.rstrip())
|
|
||||||
l = want.find('\n', l)
|
|
||||||
if l >= 0:
|
|
||||||
want = want[:l]
|
|
||||||
|
|
||||||
want_lines = want.split('\n')
|
want_lines = want.split('\n')
|
||||||
|
if len(want_lines) > 1 and re.match(r' *$', want_lines[-1]):
|
||||||
|
del want_lines[-1] # forget final newline & spaces after it
|
||||||
self._check_prefix(want_lines, ' '*indent, name,
|
self._check_prefix(want_lines, ' '*indent, name,
|
||||||
lineno + len(source_lines))
|
lineno + len(source_lines))
|
||||||
want = '\n'.join([wl[indent:] for wl in want_lines])
|
want = '\n'.join([wl[indent:] for wl in want_lines])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue