MCPcopy Create free account
hub / github.com/python/cpython / normalize_snippet

Function normalize_snippet

Tools/clinic/libclinic/formatting.py:152–163  ·  view source on GitHub ↗

Reformats 'text': * removes leading and trailing blank lines * ensures that it does not end with a newline * dedents so the first nonwhite character on any line is at column "indent"

(text: str, *, indent: int = 0)

Source from the content-addressed store, hash-verified

150
151@functools.lru_cache()
152def normalize_snippet(text: str, *, indent: int = 0) -> str:
153 """
154 Reformats 'text':
155 * removes leading and trailing blank lines
156 * ensures that it does not end with a newline
157 * dedents so the first nonwhite character on any line is at column "indent"
158 """
159 text = _strip_leading_and_trailing_blank_lines(text)
160 text = textwrap.dedent(text)
161 if indent:
162 text = textwrap.indent(text, " " * indent)
163 return text
164
165
166def format_escape(text: str) -> str:

Callers

nothing calls this directly

Calls 3

dedentMethod · 0.45
indentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…