From c951a24730b1e07885e2b68fa2c0997e25d3434e Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 7 Jul 2017 00:55:46 +0200 Subject: [PATCH] Some more fixes. Test run now with pytest -k 'not E12' under Python 3.5. --- parso/python/normalizer.py | 19 +++++++++++++------ test/normalizer_issue_files/E12_third.py | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index ba1eb05..34fcc59 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -70,7 +70,8 @@ class IndentationNode(object): class BracketNode(IndentationNode): - def __init__(self, config, parent_indentation, leaf, parent): + def __init__(self, config, parent_indentation, leaf, parent, + in_suite_introducer=False): self.leaf = leaf next_leaf = leaf.get_next_leaf() @@ -97,6 +98,12 @@ class BracketNode(IndentationNode): self.indentation = ' ' * expected_end_indent self.bracket_indentation = self.indentation self.type = IndentationTypes.VERTICAL_BRACKET + + if in_suite_introducer and parent.type == IndentationTypes.SUITE \ + and self.indentation == parent_indentation + config.indentation: + self.indentation += config.indentation + # The closing bracket should have the same indentation. + self.bracket_indentation = self.indentation self.parent = parent @@ -346,6 +353,8 @@ class PEP8Normalizer(Normalizer): if leaf.value == ':' and leaf.parent.type in _SUITE_INTRODUCERS: self._in_suite_introducer = False + elif leaf.value == 'elif': + self._in_suite_introducer = True if not self._new_statement: self._reset_newlines(part, leaf) @@ -477,13 +486,11 @@ class PEP8Normalizer(Normalizer): if not isinstance(n, BracketNode) or previous_leaf != n.leaf: break n = n.parent - indentation = n.indentation - if self._in_suite_introducer and node.type == IndentationTypes.SUITE: - indentation += self._config.indentation self._indentation_tos = BracketNode( - self._config, indentation, leaf, - parent=self._indentation_tos + self._config, n.indentation, leaf, + parent=self._indentation_tos, + in_suite_introducer=self._in_suite_introducer ) else: assert node.type != IndentationTypes.IMPLICIT diff --git a/test/normalizer_issue_files/E12_third.py b/test/normalizer_issue_files/E12_third.py index 288ec51..0957737 100644 --- a/test/normalizer_issue_files/E12_third.py +++ b/test/normalizer_issue_files/E12_third.py @@ -77,7 +77,7 @@ if True: def example_issue254(): #: return [node.copy( - #: E121:12 + #: E121:12 ( #: E121:16 E126+1:24 E126+2:24 replacement