Commit e411b662 authored by Dingyuan Wang's avatar Dingyuan Wang

Issue #20387: Restore retention of indentation during untokenize.

parent b6d1cdda
...@@ -244,6 +244,8 @@ class Untokenizer: ...@@ -244,6 +244,8 @@ class Untokenizer:
def untokenize(self, iterable): def untokenize(self, iterable):
it = iter(iterable) it = iter(iterable)
indents = []
startline = False
for t in it: for t in it:
if len(t) == 2: if len(t) == 2:
self.compat(t, it) self.compat(t, it)
...@@ -254,6 +256,21 @@ class Untokenizer: ...@@ -254,6 +256,21 @@ class Untokenizer:
continue continue
if tok_type == ENDMARKER: if tok_type == ENDMARKER:
break break
if tok_type == INDENT:
indents.append(token)
continue
elif tok_type == DEDENT:
indents.pop()
self.prev_row, self.prev_col = end
continue
elif tok_type in (NEWLINE, NL):
startline = True
elif startline and indents:
indent = indents[-1]
if start[1] >= len(indent):
self.tokens.append(indent)
self.prev_col = len(indent)
startline = False
self.add_whitespace(start) self.add_whitespace(start)
self.tokens.append(token) self.tokens.append(token)
self.prev_row, self.prev_col = end self.prev_row, self.prev_col = end
......
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