mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-21 03:42:00 +08:00
Better backslash nodes that allow other alignments in case of expr_stmt.
This commit is contained in:
@@ -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,8 +140,20 @@ 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):
|
||||||
self.bracket_indentation = self.indentation = parent_indentation + config.indentation
|
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
|
||||||
|
|
||||||
|
|
||||||
def _is_magic_name(name):
|
def _is_magic_name(name):
|
||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user