Better backslash nodes that allow other alignments in case of expr_stmt.

This commit is contained in:
Dave Halter
2017-06-21 17:25:00 +02:00
parent cd1b676c7e
commit e66b62d1e1

View File

@@ -114,11 +114,11 @@ class BracketNode(IndentationNode):
# a, # a,
# b, # b,
# ) # )
self.expected_end_indent = leaf.end_pos[1] expected_end_indent = leaf.end_pos[1]
if '\t' in config.indentation: if '\t' in config.indentation:
self.indentation = None self.indentation = None
else: else:
self.indentation = ' ' * self.expected_end_indent self.indentation = ' ' * expected_end_indent
self.bracket_indentation = self.indentation self.bracket_indentation = self.indentation
self.type = IndentationTypes.VERTICAL_BRACKET self.type = IndentationTypes.VERTICAL_BRACKET
@@ -140,7 +140,19 @@ class ImplicitNode(BracketNode):
class BackslashNode(IndentationNode): class BackslashNode(IndentationNode):
type = IndentationTypes.BACKSLASH type = IndentationTypes.BACKSLASH
def __init__(self, config, parent_indentation): def __init__(self, config, parent_indentation, containing_leaf):
from parso.python.tree import search_ancestor
expr_stmt = search_ancestor(containing_leaf, 'expr_stmt')
if expr_stmt is not None:
equals = expr_stmt.children[-2]
if '\t' in config.indentation:
# TODO unite with the code of BracketNode
self.indentation = None
else:
# +1 because there is a space.
self.indentation = ' ' * (equals.end_pos[1] + 1)
else:
self.bracket_indentation = self.indentation = parent_indentation + config.indentation self.bracket_indentation = self.indentation = parent_indentation + config.indentation
@@ -275,7 +287,8 @@ class PEP8Normalizer(Normalizer):
node = BackslashNode( node = BackslashNode(
self._config, self._config,
indentation indentation,
leaf
) )
self._indentation_stack.append(node) self._indentation_stack.append(node)