MCPcopy Create free account
hub / github.com/ipython/ipython / strip_initial_indent

Function strip_initial_indent

IPython/core/magics/code.py:136–164  ·  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

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

Callers 1

loadMethod · 0.85

Calls 1

groupMethod · 0.80

Tested by

no test coverage detected