mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-19 23:10:16 +08:00
PEP 8
This commit is contained in:
+13
-12
@@ -6,7 +6,6 @@ from contextlib import contextmanager
|
|||||||
|
|
||||||
from parso.normalizer import Normalizer, NormalizerConfig, Issue, Rule
|
from parso.normalizer import Normalizer, NormalizerConfig, Issue, Rule
|
||||||
from parso.python.tree import search_ancestor
|
from parso.python.tree import search_ancestor
|
||||||
from parso.parser import ParserSyntaxError
|
|
||||||
|
|
||||||
_BLOCK_STMTS = ('if_stmt', 'while_stmt', 'for_stmt', 'try_stmt', 'with_stmt')
|
_BLOCK_STMTS = ('if_stmt', 'while_stmt', 'for_stmt', 'try_stmt', 'with_stmt')
|
||||||
_STAR_EXPR_PARENTS = ('testlist_star_expr', 'testlist_comp', 'exprlist')
|
_STAR_EXPR_PARENTS = ('testlist_star_expr', 'testlist_comp', 'exprlist')
|
||||||
@@ -107,6 +106,7 @@ def _iter_definition_exprs_from_lists(exprlist):
|
|||||||
|
|
||||||
yield child
|
yield child
|
||||||
|
|
||||||
|
|
||||||
def _get_expr_stmt_definition_exprs(expr_stmt):
|
def _get_expr_stmt_definition_exprs(expr_stmt):
|
||||||
exprs = []
|
exprs = []
|
||||||
for list_ in expr_stmt.children[:-2:2]:
|
for list_ in expr_stmt.children[:-2:2]:
|
||||||
@@ -273,13 +273,12 @@ class ErrorFinder(Normalizer):
|
|||||||
def visit(self, node):
|
def visit(self, node):
|
||||||
if node.type == 'error_node':
|
if node.type == 'error_node':
|
||||||
with self.visit_node(node):
|
with self.visit_node(node):
|
||||||
# Don't need to investigate the inners of an error node. We
|
# Don't need to investigate the inners of an error node. We
|
||||||
# might find errors in there that should be ignored, because
|
# might find errors in there that should be ignored, because
|
||||||
# the error node itself already shows that there's an issue.
|
# the error node itself already shows that there's an issue.
|
||||||
return ''
|
return ''
|
||||||
return super(ErrorFinder, self).visit(node)
|
return super(ErrorFinder, self).visit(node)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def visit_node(self, node):
|
def visit_node(self, node):
|
||||||
self._check_type_rules(node)
|
self._check_type_rules(node)
|
||||||
@@ -455,7 +454,7 @@ class _YieldFromCheck(SyntaxRule):
|
|||||||
|
|
||||||
def is_issue(self, leaf):
|
def is_issue(self, leaf):
|
||||||
return leaf.parent.type == 'yield_arg' \
|
return leaf.parent.type == 'yield_arg' \
|
||||||
and self._normalizer.context.is_async_funcdef()
|
and self._normalizer.context.is_async_funcdef()
|
||||||
|
|
||||||
|
|
||||||
@ErrorFinder.register_rule(type='name')
|
@ErrorFinder.register_rule(type='name')
|
||||||
@@ -618,7 +617,7 @@ class _FutureImportRule(SyntaxRule):
|
|||||||
allowed_futures.append('generator_stop')
|
allowed_futures.append('generator_stop')
|
||||||
|
|
||||||
if name == 'braces':
|
if name == 'braces':
|
||||||
self.add_issue(node, message = "not a chance")
|
self.add_issue(node, message="not a chance")
|
||||||
elif name == 'barry_as_FLUFL':
|
elif name == 'barry_as_FLUFL':
|
||||||
m = "Seriously I'm not implementing this :) ~ Dave"
|
m = "Seriously I'm not implementing this :) ~ Dave"
|
||||||
self.add_issue(node, message=m)
|
self.add_issue(node, message=m)
|
||||||
@@ -715,8 +714,8 @@ class _AnnotatorRule(SyntaxRule):
|
|||||||
if not (lhs.type == 'name'
|
if not (lhs.type == 'name'
|
||||||
# subscript/attributes are allowed
|
# subscript/attributes are allowed
|
||||||
or lhs.type in ('atom_expr', 'power')
|
or lhs.type in ('atom_expr', 'power')
|
||||||
and trailer.type == 'trailer'
|
and trailer.type == 'trailer'
|
||||||
and trailer.children[0] != '('):
|
and trailer.children[0] != '('):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
# x, y: str
|
# x, y: str
|
||||||
@@ -787,7 +786,8 @@ class _ArglistRule(SyntaxRule):
|
|||||||
if first == '*':
|
if first == '*':
|
||||||
if kw_unpacking_only:
|
if kw_unpacking_only:
|
||||||
# foo(**kwargs, *args)
|
# foo(**kwargs, *args)
|
||||||
message = "iterable argument unpacking follows keyword argument unpacking"
|
message = "iterable argument unpacking " \
|
||||||
|
"follows keyword argument unpacking"
|
||||||
self.add_issue(argument, message=message)
|
self.add_issue(argument, message=message)
|
||||||
else:
|
else:
|
||||||
kw_unpacking_only = True
|
kw_unpacking_only = True
|
||||||
@@ -809,6 +809,7 @@ class _ArglistRule(SyntaxRule):
|
|||||||
message = "positional argument follows keyword argument"
|
message = "positional argument follows keyword argument"
|
||||||
self.add_issue(argument, message=message)
|
self.add_issue(argument, message=message)
|
||||||
|
|
||||||
|
|
||||||
@ErrorFinder.register_rule(type='parameters')
|
@ErrorFinder.register_rule(type='parameters')
|
||||||
@ErrorFinder.register_rule(type='lambdef')
|
@ErrorFinder.register_rule(type='lambdef')
|
||||||
class _ParameterRule(SyntaxRule):
|
class _ParameterRule(SyntaxRule):
|
||||||
@@ -929,7 +930,7 @@ class _CheckAssignmentRule(SyntaxRule):
|
|||||||
elif type_ in ('testlist_star_expr', 'exprlist', 'testlist'):
|
elif type_ in ('testlist_star_expr', 'exprlist', 'testlist'):
|
||||||
for child in node.children[::2]:
|
for child in node.children[::2]:
|
||||||
self._check_assignment(child, is_deletion)
|
self._check_assignment(child, is_deletion)
|
||||||
elif ('expr' in type_ and type_ != 'star_expr' # is a substring
|
elif ('expr' in type_ and type_ != 'star_expr' # is a substring
|
||||||
or '_test' in type_
|
or '_test' in type_
|
||||||
or type_ in ('term', 'factor')):
|
or type_ in ('term', 'factor')):
|
||||||
error = 'operator'
|
error = 'operator'
|
||||||
|
|||||||
Reference in New Issue
Block a user