Move INDENT value to the postponed prefix
This makes blib2to3's tree output valid again (which was broken by the previous fiddling with INDENT and DEDENT nodes). Fixes #334
This commit is contained in:
parent
df2ae3bbe6
commit
e1ef57a29e
@ -830,6 +830,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
|
|||||||
|
|
||||||
* they now correctly work across function/class boundaries (#335)
|
* they now correctly work across function/class boundaries (#335)
|
||||||
|
|
||||||
|
* they now work when an indentation block starts with empty lines or misaligned
|
||||||
|
comments (#334)
|
||||||
|
|
||||||
* fixed improper formatting of f-strings with quotes inside interpolated
|
* fixed improper formatting of f-strings with quotes inside interpolated
|
||||||
expressions (#322)
|
expressions (#322)
|
||||||
|
|
||||||
|
@ -70,24 +70,19 @@ 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 in {token.INDENT, token.DEDENT}:
|
if type == token.INDENT:
|
||||||
_prefix = prefix
|
indent_columns.append(len(value))
|
||||||
|
_prefix = prefix + value
|
||||||
prefix = ""
|
prefix = ""
|
||||||
if type == token.DEDENT:
|
value = ""
|
||||||
|
elif type == token.DEDENT:
|
||||||
_indent_col = indent_columns.pop()
|
_indent_col = indent_columns.pop()
|
||||||
prefix, _prefix = self._partially_consume_prefix(_prefix, _indent_col)
|
prefix, _prefix = self._partially_consume_prefix(prefix, _indent_col)
|
||||||
if p.addtoken(type, value, (prefix, start)):
|
if p.addtoken(type, value, (prefix, start)):
|
||||||
if debug:
|
if debug:
|
||||||
self.logger.debug("Stop.")
|
self.logger.debug("Stop.")
|
||||||
break
|
break
|
||||||
prefix = ""
|
prefix = ""
|
||||||
if type == token.INDENT:
|
|
||||||
indent_columns.append(len(value))
|
|
||||||
if _prefix.startswith(value):
|
|
||||||
# Don't double-indent. Since we're delaying the prefix that
|
|
||||||
# would normally belong to INDENT, we need to put the value
|
|
||||||
# at the end versus at the beginning.
|
|
||||||
_prefix = _prefix[len(value):] + value
|
|
||||||
if type in {token.INDENT, token.DEDENT}:
|
if type in {token.INDENT, token.DEDENT}:
|
||||||
prefix = _prefix
|
prefix = _prefix
|
||||||
lineno, column = end
|
lineno, column = end
|
||||||
|
@ -36,10 +36,11 @@ file_input
|
|||||||
NEWLINE
|
NEWLINE
|
||||||
'\n'
|
'\n'
|
||||||
INDENT
|
INDENT
|
||||||
' '
|
''
|
||||||
simple_stmt
|
simple_stmt
|
||||||
expr_stmt
|
expr_stmt
|
||||||
NAME
|
NAME
|
||||||
|
' '
|
||||||
'tree_depth'
|
'tree_depth'
|
||||||
annassign
|
annassign
|
||||||
COLON
|
COLON
|
||||||
@ -109,10 +110,11 @@ file_input
|
|||||||
NEWLINE
|
NEWLINE
|
||||||
'\n'
|
'\n'
|
||||||
INDENT
|
INDENT
|
||||||
' '
|
''
|
||||||
simple_stmt
|
simple_stmt
|
||||||
expr_stmt
|
expr_stmt
|
||||||
NAME
|
NAME
|
||||||
|
' '
|
||||||
'indent'
|
'indent'
|
||||||
EQUAL
|
EQUAL
|
||||||
' '
|
' '
|
||||||
@ -184,10 +186,11 @@ file_input
|
|||||||
NEWLINE
|
NEWLINE
|
||||||
'\n'
|
'\n'
|
||||||
INDENT
|
INDENT
|
||||||
' '
|
''
|
||||||
simple_stmt
|
simple_stmt
|
||||||
expr_stmt
|
expr_stmt
|
||||||
NAME
|
NAME
|
||||||
|
' '
|
||||||
'_type'
|
'_type'
|
||||||
EQUAL
|
EQUAL
|
||||||
' '
|
' '
|
||||||
@ -297,10 +300,11 @@ file_input
|
|||||||
NEWLINE
|
NEWLINE
|
||||||
'\n'
|
'\n'
|
||||||
INDENT
|
INDENT
|
||||||
' '
|
''
|
||||||
simple_stmt
|
simple_stmt
|
||||||
yield_expr
|
yield_expr
|
||||||
NAME
|
NAME
|
||||||
|
' '
|
||||||
'yield'
|
'yield'
|
||||||
yield_arg
|
yield_arg
|
||||||
NAME
|
NAME
|
||||||
@ -410,10 +414,11 @@ file_input
|
|||||||
NEWLINE
|
NEWLINE
|
||||||
'\n'
|
'\n'
|
||||||
INDENT
|
INDENT
|
||||||
' '
|
''
|
||||||
simple_stmt
|
simple_stmt
|
||||||
expr_stmt
|
expr_stmt
|
||||||
NAME
|
NAME
|
||||||
|
' '
|
||||||
'_type'
|
'_type'
|
||||||
EQUAL
|
EQUAL
|
||||||
' '
|
' '
|
||||||
@ -542,11 +547,11 @@ file_input
|
|||||||
NEWLINE
|
NEWLINE
|
||||||
'\n'
|
'\n'
|
||||||
INDENT
|
INDENT
|
||||||
' '
|
''
|
||||||
simple_stmt
|
simple_stmt
|
||||||
power
|
power
|
||||||
NAME
|
NAME
|
||||||
"# We don't have to handle prefixes for `Node` objects since\n # that delegates to the first child anyway.\n "
|
" # We don't have to handle prefixes for `Node` objects since\n # that delegates to the first child anyway.\n "
|
||||||
'out'
|
'out'
|
||||||
trailer
|
trailer
|
||||||
LPAR
|
LPAR
|
||||||
@ -699,9 +704,10 @@ file_input
|
|||||||
NEWLINE
|
NEWLINE
|
||||||
'\n'
|
'\n'
|
||||||
INDENT
|
INDENT
|
||||||
' '
|
''
|
||||||
simple_stmt
|
simple_stmt
|
||||||
STRING
|
STRING
|
||||||
|
' '
|
||||||
'"""Pretty-prints a given string of `code`.\n\n Convenience method for debugging.\n """'
|
'"""Pretty-prints a given string of `code`.\n\n Convenience method for debugging.\n """'
|
||||||
NEWLINE
|
NEWLINE
|
||||||
'\n'
|
'\n'
|
||||||
|
@ -19,8 +19,17 @@ def test_fader(test):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def check_fader(test):
|
def check_fader(test):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def verify_fader(test):
|
||||||
|
# misaligned comment
|
||||||
|
pass
|
||||||
|
|
||||||
|
def verify_fader(test):
|
||||||
|
"""Hey, ho."""
|
||||||
|
assert test.passed()
|
||||||
|
|
||||||
def test_calculate_fades():
|
def test_calculate_fades():
|
||||||
calcs = [
|
calcs = [
|
||||||
# one is zero/none
|
# one is zero/none
|
||||||
|
Loading…
Reference in New Issue
Block a user