Commit d8be3ad8 authored by Stefan Behnel's avatar Stefan Behnel

fix exception in cython.inline() when text block to dedent starts without initial indentation

parent 762b3151
...@@ -221,27 +221,29 @@ def __invoke(%(params)s): ...@@ -221,27 +221,29 @@ def __invoke(%(params)s):
# overridden with actual value upon the first cython_inline invocation # overridden with actual value upon the first cython_inline invocation
cython_inline.so_ext = None cython_inline.so_ext = None
non_space = re.compile('[^ ]') _find_non_space = re.compile('[^ ]').search
def strip_common_indent(code): def strip_common_indent(code):
min_indent = None min_indent = None
lines = code.split('\n') lines = code.splitlines()
for line in lines: for line in lines:
match = non_space.search(line) match = _find_non_space(line)
if not match: if not match:
continue # blank continue # blank
indent = match.start() indent = match.start()
if line[indent] == '#': if line[indent] == '#':
continue # comment continue # comment
elif min_indent is None or min_indent > indent: if min_indent is None or min_indent > indent:
min_indent = indent min_indent = indent
for ix, line in enumerate(lines): for ix, line in enumerate(lines):
match = non_space.search(line) match = _find_non_space(line)
if not match or line[indent] == '#': if not match or not line or line[indent:indent+1] == '#':
continue continue
else:
lines[ix] = line[min_indent:] lines[ix] = line[min_indent:]
return '\n'.join(lines) return '\n'.join(lines)
module_statement = re.compile(r'^((cdef +(extern|class))|cimport|(from .+ cimport)|(from .+ import +[*]))') module_statement = re.compile(r'^((cdef +(extern|class))|cimport|(from .+ cimport)|(from .+ import +[*]))')
def extract_func_code(code): def extract_func_code(code):
module = [] module = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment