MCPcopy
hub / github.com/prompt-toolkit/ptpython / unindent_code

Function unindent_code

src/ptpython/utils.py:179–191  ·  view source on GitHub ↗

Remove common leading whitespace when all lines are indented.

(text: str)

Source from the content-addressed store, hash-verified

177
178
179def unindent_code(text: str) -> str:
180 """
181 Remove common leading whitespace when all lines are indented.
182 """
183 lines = text.splitlines(keepends=True)
184
185 # Look for common prefix.
186 common_prefix = _common_whitespace_prefix(lines)
187
188 # Remove indentation.
189 lines = [line[len(common_prefix) :] for line in lines]
190
191 return "".join(lines)
192
193
194def _common_whitespace_prefix(strings: Iterable[str]) -> str:

Callers 2

validateMethod · 0.85
readMethod · 0.85

Calls 1

Tested by

no test coverage detected