def _postprocess_eval_line(self, evalline, fname, span):
lines = evalline.split('\n')
# If line ended on '\n', last element is ''. We remove it and
# add the trailing newline later manually.
trailing_newline = (lines[-1] == '')
if trailing_newline:
del lines[-1]
lnum = linenumdir(span[0], fname) if self._linenums else ''
clnum = lnum if self._contlinenums else ''
linenumsep = '\n' + lnum
clinenumsep = '\n' + clnum
foldedlines = [self._foldline(line) for line in lines]
outlines = [clinenumsep.join(lines) for lines in foldedlines]
result = linenumsep.join(outlines)
# Add missing trailing newline
if trailing_newline:
trailing = '\n'
if self._linenums:
# Last line was folded, but no linenums were generated for
# the continuation lines -> current line position is not
# in sync with the one calculated from the last line number
unsync = (
len(foldedlines) and len(foldedlines[-1]) > 1
and not self._contlinenums)
# Eval directive in source consists of more than one line
multiline = span[1] - span[0] > 1
if unsync or multiline:
# For inline eval directives span[0] == span[1]
# -> next line is span[0] + 1 and not span[1] as for
# line eval directives
nextline = max(span[1], span[0] + 1)
trailing += linenumdir(nextline, fname)
else:
trailing = ''
return result + trailing
评论列表
文章目录