MCPcopy Index your code
hub / github.com/ipython/ipython / strip_initial_indent

Function strip_initial_indent

IPython/core/magics/code.py:138–168  ·  view source on GitHub ↗

For %load, strip indent from lines until finding an unindented line. https://github.com/ipython/ipython/issues/9775

(lines)

Source from the content-addressed store, hash-verified

136 return blocks, not_found
137
138def strip_initial_indent(lines):
139 """For %load, strip indent from lines until finding an unindented line.
140
141 https://github.com/ipython/ipython/issues/9775
142 """
143 indent_re = re.compile(r'\s+')
144
145 it = iter(lines)
146 first_line = next(it)
147 indent_match = indent_re.match(first_line)
148
149 if indent_match:
150 # First line was indented
151 indent = indent_match.group()
152 yield first_line[len(indent):]
153
154 for line in it:
155 if line.startswith(indent):
156 yield line[len(indent) :]
157 elif line in ("\n", "\r\n") or len(line) == 0:
158 yield line
159 else:
160 # Less indented than the first line - stop dedenting
161 yield line
162 break
163 else:
164 yield first_line
165
166 # Pass the remaining lines through without dedenting
167 for line in it:
168 yield line
169
170
171class InteractivelyDefined(Exception):

Callers 1

loadMethod · 0.85

Calls 2

matchMethod · 0.80
groupMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…