blib2to3: Never put prefixes on INDENT leaves either

This commit is contained in:
Łukasz Langa 2018-03-23 17:12:20 -07:00
parent 7e1c5b2ba6
commit 8c565d8684
5 changed files with 11 additions and 8 deletions

View File

@ -7,5 +7,6 @@ Reasons for forking:
*args and **kwargs *args and **kwargs
- backport of GH-6143 that restores the ability to reformat legacy usage of - backport of GH-6143 that restores the ability to reformat legacy usage of
`async` `async`
- better ability to debug (better reprs for starters) - better ability to debug (better reprs)
- INDENT and DEDENT don't hold whitespace and comment prefixes
- ability to Cythonize - ability to Cythonize

View File

@ -69,7 +69,7 @@ def parse_tokens(self, tokens, debug=False):
if debug: if debug:
self.logger.debug("%s %r (prefix=%r)", self.logger.debug("%s %r (prefix=%r)",
token.tok_name[type], value, prefix) token.tok_name[type], value, prefix)
if type == token.DEDENT: if type in {token.INDENT, token.DEDENT}:
_prefix = prefix _prefix = prefix
prefix = "" prefix = ""
if p.addtoken(type, value, (prefix, start)): if p.addtoken(type, value, (prefix, start)):
@ -77,7 +77,7 @@ def parse_tokens(self, tokens, debug=False):
self.logger.debug("Stop.") self.logger.debug("Stop.")
break break
prefix = "" prefix = ""
if type == token.DEDENT: if type in {token.INDENT, token.DEDENT}:
prefix = _prefix prefix = _prefix
lineno, column = end lineno, column = end
if value.endswith("\n"): if value.endswith("\n"):

View File

@ -430,6 +430,10 @@ def generate_tokens(readline):
yield stashed yield stashed
stashed = None stashed = None
if column > indents[-1]: # count indents
indents.append(column)
yield (INDENT, line[:pos], (lnum, 0), (lnum, pos), line)
if line[pos] in '#\r\n': # skip comments or blank lines if line[pos] in '#\r\n': # skip comments or blank lines
if line[pos] == '#': if line[pos] == '#':
comment_token = line[pos:].rstrip('\r\n') comment_token = line[pos:].rstrip('\r\n')
@ -443,10 +447,7 @@ def generate_tokens(readline):
(lnum, pos), (lnum, len(line)), line) (lnum, pos), (lnum, len(line)), line)
continue continue
if column > indents[-1]: # count indents or dedents while column < indents[-1]: # count dedents
indents.append(column)
yield (INDENT, line[:pos], (lnum, 0), (lnum, pos), line)
while column < indents[-1]:
if column not in indents: if column not in indents:
raise IndentationError( raise IndentationError(
"unindent does not match any outer indentation level", "unindent does not match any outer indentation level",

View File

@ -105,6 +105,7 @@ def f():
if not prev: if not prev:
prevp = preceding_leaf(p) prevp = preceding_leaf(p)
if not prevp or prevp.type in OPENING_BRACKETS: if not prevp or prevp.type in OPENING_BRACKETS:
return NO return NO
if prevp.type == token.EQUAL: if prevp.type == token.EQUAL: