mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-25 01:38:52 +08:00
Move some star_expr checking around.
This commit is contained in:
+10
-10
@@ -87,20 +87,20 @@ class Normalizer(use_metaclass(_NormalizerMeta)):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _register_rule(cls, value=None, values=(), type=None, types=()):
|
def _register_rule(cls, value=None, values=(), type=None, types=()):
|
||||||
if value is None and type is None:
|
values = list(values)
|
||||||
|
types = list(types)
|
||||||
|
if value is not None:
|
||||||
|
values.append(value)
|
||||||
|
if type is not None:
|
||||||
|
types.append(type)
|
||||||
|
|
||||||
|
if not values and not types:
|
||||||
raise ValueError("You must register at least something.")
|
raise ValueError("You must register at least something.")
|
||||||
|
|
||||||
def decorator(rule_cls):
|
def decorator(rule_cls):
|
||||||
copied_values = list(values)
|
for v in values:
|
||||||
copied_types = list(types)
|
|
||||||
if value is not None:
|
|
||||||
copied_values.append(value)
|
|
||||||
if type is not None:
|
|
||||||
copied_types.append(type)
|
|
||||||
|
|
||||||
for v in copied_values:
|
|
||||||
cls.rule_value_classes.setdefault(v, []).append(rule_cls)
|
cls.rule_value_classes.setdefault(v, []).append(rule_cls)
|
||||||
for t in copied_types:
|
for t in types:
|
||||||
cls.rule_type_classes.setdefault(t, []).append(rule_cls)
|
cls.rule_type_classes.setdefault(t, []).append(rule_cls)
|
||||||
return rule_cls
|
return rule_cls
|
||||||
|
|
||||||
|
|||||||
+32
-28
@@ -289,34 +289,6 @@ class ErrorFinder(Normalizer):
|
|||||||
self._add_syntax_error(node, "too many statically nested blocks")
|
self._add_syntax_error(node, "too many statically nested blocks")
|
||||||
yield
|
yield
|
||||||
return
|
return
|
||||||
elif node.type in _STAR_EXPR_PARENTS:
|
|
||||||
if node.parent.type == 'del_stmt':
|
|
||||||
self._add_syntax_error(node.parent, "can't use starred expression here")
|
|
||||||
else:
|
|
||||||
def is_definition(node, ancestor):
|
|
||||||
if ancestor is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
type_ = ancestor.type
|
|
||||||
if type_ == 'trailer':
|
|
||||||
return False
|
|
||||||
|
|
||||||
if type_ == 'expr_stmt':
|
|
||||||
return node.start_pos < ancestor.children[-1].start_pos
|
|
||||||
|
|
||||||
return is_definition(node, ancestor.parent)
|
|
||||||
|
|
||||||
if is_definition(node, node.parent):
|
|
||||||
args = [c for c in node.children if c != ',']
|
|
||||||
starred = [c for c in args if c.type == 'star_expr']
|
|
||||||
if len(starred) > 1:
|
|
||||||
message = "two starred expressions in assignment"
|
|
||||||
self._add_syntax_error(starred[1], message)
|
|
||||||
elif starred:
|
|
||||||
count = args.index(starred[0])
|
|
||||||
if count >= 256:
|
|
||||||
message = "too many expressions in star-unpacking assignment"
|
|
||||||
self._add_syntax_error(starred[0], message)
|
|
||||||
elif node.type == 'suite':
|
elif node.type == 'suite':
|
||||||
self._indentation_count += 1
|
self._indentation_count += 1
|
||||||
if self._indentation_count == _MAX_INDENT_COUNT:
|
if self._indentation_count == _MAX_INDENT_COUNT:
|
||||||
@@ -678,6 +650,38 @@ class _StarExprRule(SyntaxRule):
|
|||||||
self.add_issue(node, message=self.message_assignment)
|
self.add_issue(node, message=self.message_assignment)
|
||||||
|
|
||||||
|
|
||||||
|
@ErrorFinder.register_rule(types=_STAR_EXPR_PARENTS)
|
||||||
|
class _StarExprParentRule(SyntaxRule):
|
||||||
|
def is_issue(self, node):
|
||||||
|
if node.parent.type == 'del_stmt':
|
||||||
|
self.add_issue(node.parent, message="can't use starred expression here")
|
||||||
|
else:
|
||||||
|
def is_definition(node, ancestor):
|
||||||
|
if ancestor is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
type_ = ancestor.type
|
||||||
|
if type_ == 'trailer':
|
||||||
|
return False
|
||||||
|
|
||||||
|
if type_ == 'expr_stmt':
|
||||||
|
return node.start_pos < ancestor.children[-1].start_pos
|
||||||
|
|
||||||
|
return is_definition(node, ancestor.parent)
|
||||||
|
|
||||||
|
if is_definition(node, node.parent):
|
||||||
|
args = [c for c in node.children if c != ',']
|
||||||
|
starred = [c for c in args if c.type == 'star_expr']
|
||||||
|
if len(starred) > 1:
|
||||||
|
message = "two starred expressions in assignment"
|
||||||
|
self.add_issue(starred[1], message=message)
|
||||||
|
elif starred:
|
||||||
|
count = args.index(starred[0])
|
||||||
|
if count >= 256:
|
||||||
|
message = "too many expressions in star-unpacking assignment"
|
||||||
|
self.add_issue(starred[0], message=message)
|
||||||
|
|
||||||
|
|
||||||
@ErrorFinder.register_rule(type='annassign')
|
@ErrorFinder.register_rule(type='annassign')
|
||||||
class _AnnotatorRule(SyntaxRule):
|
class _AnnotatorRule(SyntaxRule):
|
||||||
# True: int
|
# True: int
|
||||||
|
|||||||
Reference in New Issue
Block a user