MCPcopy Create free account
hub / github.com/pytest-dev/pytest / strip

Method strip

src/_pytest/_code/source.py:72–81  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

70 return len(self.lines)
71
72 def strip(self) -> "Source":
73 """Return new Source object with trailing and leading blank lines removed."""
74 start, end = 0, len(self)
75 while start < end and not self.lines[start].strip():
76 start += 1
77 while end > start and not self.lines[end - 1].strip():
78 end -= 1
79 source = Source()
80 source.lines[:] = self.lines[start:end]
81 return source
82
83 def indent(self, indent: str = " " * 4) -> "Source":
84 """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
__getattr__Method · 0.80
get_sourceMethod · 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
test_repr_sourceMethod · 0.64
setup_classMethod · 0.64