cpython: ff47efeeed48 (original) (raw)
Mercurial > cpython
changeset 96709:ff47efeeed48 3.4
Issue #20387: Restore retention of indentation during untokenize. [#20387]
Dingyuan Wang abcdoyle888@gmail.com | |
---|---|
date | Mon, 22 Jun 2015 10:01:12 +0800 |
parents | 49323e5f6391 |
children | 4856ae883041 |
files | Lib/tokenize.py |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-)[+] [-] Lib/tokenize.py 17 |
line wrap: on
line diff
--- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -244,6 +244,8 @@ class Untokenizer: def untokenize(self, iterable): it = iter(iterable)
indents = [][](#l1.7)
startline = False[](#l1.8) for t in it:[](#l1.9) if len(t) == 2:[](#l1.10) self.compat(t, it)[](#l1.11)
@@ -254,6 +256,21 @@ class Untokenizer: continue if tok_type == ENDMARKER: break
if tok_type == INDENT:[](#l1.16)
indents.append(token)[](#l1.17)
continue[](#l1.18)
elif tok_type == DEDENT:[](#l1.19)
indents.pop()[](#l1.20)
self.prev_row, self.prev_col = end[](#l1.21)
continue[](#l1.22)
elif tok_type in (NEWLINE, NL):[](#l1.23)
startline = True[](#l1.24)
elif startline and indents:[](#l1.25)
indent = indents[-1][](#l1.26)
if start[1] >= len(indent):[](#l1.27)
self.tokens.append(indent)[](#l1.28)
self.prev_col = len(indent)[](#l1.29)
startline = False[](#l1.30) self.add_whitespace(start)[](#l1.31) self.tokens.append(token)[](#l1.32) self.prev_row, self.prev_col = end[](#l1.33)