From 556ee2aec653e598e56fad9bdb178899a46515a1 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 31 Mar 2018 14:25:37 +0100 Subject: [PATCH] minimize_source: Handling indentation In the case that string(s) are replaced, any indent or dedent tags must be re-inserted after the replacemnts. --- mitogen/parent.py | 5 ++++- tests/data/minimize_samples/obstacle_course.py | 2 +- tests/data/minimize_samples/obstacle_course_min.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mitogen/parent.py b/mitogen/parent.py index 00b0c3aa..cfe125e2 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -120,13 +120,16 @@ def strip_docstrings(tokens): if state == 'wait_string': if typ in (tokenize.NL, tokenize.COMMENT): yield t - elif typ == tokenize.STRING: + elif typ in (tokenize.DEDENT, tokenize.INDENT, tokenize.STRING): stack.append(t) elif typ == tokenize.NEWLINE: stack.append(t) start_line, end_line = stack[0][2][0], stack[-1][3][0]+1 for i in range(start_line, end_line): yield tokenize.NL, '\n', (i, 0), (i,1), '\n' + for t in stack: + if t[0] in (tokenize.DEDENT, tokenize.INDENT): + yield t[0], t[1], (i+1, t[2][1]), (i+1, t[3][1]), t[4] del stack[:] else: stack.append(t) diff --git a/tests/data/minimize_samples/obstacle_course.py b/tests/data/minimize_samples/obstacle_course.py index c44a55c8..8e5b433c 100644 --- a/tests/data/minimize_samples/obstacle_course.py +++ b/tests/data/minimize_samples/obstacle_course.py @@ -45,5 +45,5 @@ class c2(object): "docstring" def inner(): pass d = {'a':0} - for x in '': + for x in '': # FIXME Removing this leaves nothing, hence a SyntaxError "justastring" diff --git a/tests/data/minimize_samples/obstacle_course_min.py b/tests/data/minimize_samples/obstacle_course_min.py index cee5df60..9c5a243a 100644 --- a/tests/data/minimize_samples/obstacle_course_min.py +++ b/tests/data/minimize_samples/obstacle_course_min.py @@ -46,4 +46,4 @@ class c2(object): def inner(): pass d = {'a':0} for x in '': - "justastring" +