MCPcopy
hub / github.com/pytest-dev/pytest / strip

Method strip

src/_pytest/_code/source.py:75–85  ·  src/_pytest/_code/source.py::Source.strip

Return new Source object with trailing and leading blank lines removed.

(self)

Source from the content-addressed store, hash-verified

73 return len(self.lines)
74
75 def strip(self) -> Source:
76 class="st">""class="st">"Return new Source object with trailing and leading blank lines removed."class="st">""
77 start, end = 0, len(self)
78 while start < end and not self.lines[start].strip():
79 start += 1
80 while end > start and not self.lines[end - 1].strip():
81 end -= 1
82 source = Source()
83 source.raw_lines = self.raw_lines
84 source.lines[:] = self.lines[start:end]
85 return source
86
87 def indent(self, indent: str = class="st">" " * 4) -> Source:
88 class="st">"""Return a copy of the source object with all lines indented by the

Callers 15

_getlinesMethod · 0.95
test_source_stripsFunction · 0.95
_runtest_forMethod · 0.80
_makefileMethod · 0.80
repr_failureMethod · 0.80
longreprtextMethod · 0.80
toterminalMethod · 0.80
_diff_textFunction · 0.80
joinMethod · 0.80

Calls 1

SourceClass · 0.85

Tested by 15

_getlinesMethod · 0.76
test_source_stripsFunction · 0.76
_makefileMethod · 0.64
repr_failureMethod · 0.64
test_stdinMethod · 0.64