mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-09 22:25:53 +08:00
Fix all tests. Finally.
This commit is contained in:
@@ -70,10 +70,26 @@ class IndentationNode(object):
|
|||||||
|
|
||||||
|
|
||||||
class BracketNode(IndentationNode):
|
class BracketNode(IndentationNode):
|
||||||
def __init__(self, config, parent_indentation, leaf, parent,
|
def __init__(self, config, leaf, parent, in_suite_introducer=False):
|
||||||
in_suite_introducer=False):
|
|
||||||
self.leaf = leaf
|
self.leaf = leaf
|
||||||
|
|
||||||
|
# Figure out here what the indentation is. For chained brackets
|
||||||
|
# we can basically use the previous indentation.
|
||||||
|
previous_leaf = leaf
|
||||||
|
n = parent
|
||||||
|
if n.type == IndentationTypes.IMPLICIT:
|
||||||
|
n = n.parent
|
||||||
|
while True:
|
||||||
|
if hasattr(n, 'leaf') and previous_leaf.line != n.leaf.line:
|
||||||
|
break
|
||||||
|
|
||||||
|
previous_leaf = previous_leaf.get_previous_leaf()
|
||||||
|
if not isinstance(n, BracketNode) or previous_leaf != n.leaf:
|
||||||
|
break
|
||||||
|
n = n.parent
|
||||||
|
parent_indentation = n.indentation
|
||||||
|
|
||||||
|
|
||||||
next_leaf = leaf.get_next_leaf()
|
next_leaf = leaf.get_next_leaf()
|
||||||
if '\n' in next_leaf.prefix:
|
if '\n' in next_leaf.prefix:
|
||||||
# This implies code like:
|
# This implies code like:
|
||||||
@@ -113,7 +129,8 @@ class ImplicitNode(BracketNode):
|
|||||||
annotations and dict values.
|
annotations and dict values.
|
||||||
"""
|
"""
|
||||||
def __init__(self, config, parent_indentation, leaf, parent):
|
def __init__(self, config, parent_indentation, leaf, parent):
|
||||||
super(ImplicitNode, self).__init__(config, parent_indentation, leaf, parent)
|
# TODO remove parent_indentation?
|
||||||
|
super(ImplicitNode, self).__init__(config, leaf, parent)
|
||||||
self.type = IndentationTypes.IMPLICIT
|
self.type = IndentationTypes.IMPLICIT
|
||||||
|
|
||||||
next_leaf = leaf.get_next_leaf()
|
next_leaf = leaf.get_next_leaf()
|
||||||
@@ -477,21 +494,8 @@ class PEP8Normalizer(Normalizer):
|
|||||||
if value and value in '()[]{}' and type_ != 'error_leaf' \
|
if value and value in '()[]{}' and type_ != 'error_leaf' \
|
||||||
and leaf.parent.type != 'error_node':
|
and leaf.parent.type != 'error_node':
|
||||||
if value in _OPENING_BRACKETS:
|
if value in _OPENING_BRACKETS:
|
||||||
# Figure out here what the indentation is. For chained brackets
|
|
||||||
# we can basically use the previous indentation.
|
|
||||||
previous_leaf = leaf
|
|
||||||
n = self._indentation_tos
|
|
||||||
while True:
|
|
||||||
if hasattr(n, 'leaf') and previous_leaf.line != n.leaf.line:
|
|
||||||
break
|
|
||||||
|
|
||||||
previous_leaf = previous_leaf.get_previous_leaf()
|
|
||||||
if not isinstance(n, BracketNode) or previous_leaf != n.leaf:
|
|
||||||
break
|
|
||||||
n = n.parent
|
|
||||||
|
|
||||||
self._indentation_tos = BracketNode(
|
self._indentation_tos = BracketNode(
|
||||||
self._config, n.indentation, leaf,
|
self._config, leaf,
|
||||||
parent=self._indentation_tos,
|
parent=self._indentation_tos,
|
||||||
in_suite_introducer=self._in_suite_introducer
|
in_suite_introducer=self._in_suite_introducer
|
||||||
)
|
)
|
||||||
@@ -508,6 +512,7 @@ class PEP8Normalizer(Normalizer):
|
|||||||
|
|
||||||
self._on_newline = type_ in ('newline', 'backslash')
|
self._on_newline = type_ in ('newline', 'backslash')
|
||||||
|
|
||||||
|
self._pre_previous_leaf = self._previous_leaf
|
||||||
self._previous_leaf = leaf
|
self._previous_leaf = leaf
|
||||||
self._previous_spacing = spacing
|
self._previous_spacing = spacing
|
||||||
return value
|
return value
|
||||||
@@ -607,7 +612,8 @@ class PEP8Normalizer(Normalizer):
|
|||||||
add_not_spaces(275, 'Missing whitespace around keyword', spacing)
|
add_not_spaces(275, 'Missing whitespace around keyword', spacing)
|
||||||
else:
|
else:
|
||||||
prev_spacing = self._previous_spacing
|
prev_spacing = self._previous_spacing
|
||||||
if prev in _ALLOW_SPACE and spaces != prev_spacing.value:
|
if prev in _ALLOW_SPACE and spaces != prev_spacing.value \
|
||||||
|
and '\n' not in self._actual_previous_leaf.prefix:
|
||||||
message = "Whitespace before operator doesn't match with whitespace after"
|
message = "Whitespace before operator doesn't match with whitespace after"
|
||||||
self.add_issue(229, message, spacing)
|
self.add_issue(229, message, spacing)
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ result = {
|
|||||||
rv.update(dict.fromkeys((
|
rv.update(dict.fromkeys((
|
||||||
'qualif_nr', 'reasonComment_en', 'reasonComment_fr',
|
'qualif_nr', 'reasonComment_en', 'reasonComment_fr',
|
||||||
'reasonComment_de', 'reasonComment_it'),
|
'reasonComment_de', 'reasonComment_it'),
|
||||||
#: E128
|
#: E128:10
|
||||||
'?'),
|
'?'),
|
||||||
"foo")
|
"foo")
|
||||||
|
|
||||||
@@ -74,5 +74,5 @@ part = set_mimetype((
|
|||||||
'default')
|
'default')
|
||||||
part = set_mimetype((
|
part = set_mimetype((
|
||||||
a.get('mime_type', 'text')),
|
a.get('mime_type', 'text')),
|
||||||
#: E127:21
|
#: E127:21
|
||||||
'default')
|
'default')
|
||||||
|
|||||||
@@ -267,16 +267,9 @@ if True:
|
|||||||
|
|
||||||
def valid_example():
|
def valid_example():
|
||||||
return [node.copy(properties=dict(
|
return [node.copy(properties=dict(
|
||||||
(key, val if val is not None else token.undefined)
|
(key, val if val is not None else token.undefined)
|
||||||
for key, val in node.items()
|
for key, val in node.items()
|
||||||
))]
|
))]
|
||||||
|
|
||||||
|
|
||||||
def other_example():
|
|
||||||
return [node.copy(properties=dict(
|
|
||||||
(key, val if val is not None else token.undefined)
|
|
||||||
for key, val in node.items()
|
|
||||||
))]
|
|
||||||
|
|
||||||
|
|
||||||
foo([
|
foo([
|
||||||
|
|||||||
@@ -77,14 +77,12 @@ if True:
|
|||||||
def example_issue254():
|
def example_issue254():
|
||||||
#:
|
#:
|
||||||
return [node.copy(
|
return [node.copy(
|
||||||
#: E121:12
|
(
|
||||||
(
|
#: E121:16 E121+3:20
|
||||||
#: E121:16 E126+1:24 E126+2:24
|
|
||||||
replacement
|
replacement
|
||||||
# First, look at all the node's current children.
|
# First, look at all the node's current children.
|
||||||
for child in node.children
|
for child in node.children
|
||||||
for replacement in replace(child)
|
for replacement in replace(child)
|
||||||
#: E123
|
|
||||||
),
|
),
|
||||||
dict(name=token.undefined)
|
dict(name=token.undefined)
|
||||||
)]
|
)]
|
||||||
|
|||||||
Reference in New Issue
Block a user