mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 04:44:29 +08:00
Only apply non-default params logic prior to the star (fixes #161)
This commit is contained in:
@@ -6,6 +6,7 @@ David Halter (@davidhalter) <davidhalter88@gmail.com>
|
||||
Code Contributors
|
||||
=================
|
||||
Alisdair Robertson (@robodair)
|
||||
Bryan Forbes (@bryanforbes) <bryan@reigndropsfall.net>
|
||||
|
||||
|
||||
Code Contributors (to Jedi and therefore possibly to this library)
|
||||
|
||||
@@ -160,7 +160,7 @@ def _skip_parens_bottom_up(node):
|
||||
|
||||
|
||||
def _iter_params(parent_node):
|
||||
return (n for n in parent_node.children if n.type == 'param')
|
||||
return (n for n in parent_node.children if n.type == 'param' or n.type == 'operator')
|
||||
|
||||
|
||||
def _is_future_import_first(import_from):
|
||||
@@ -942,17 +942,28 @@ class _ParameterRule(SyntaxRule):
|
||||
def is_issue(self, node):
|
||||
param_names = set()
|
||||
default_only = False
|
||||
star_seen = False
|
||||
for p in _iter_params(node):
|
||||
if p.type == 'operator':
|
||||
if p.value == '*':
|
||||
star_seen = True
|
||||
default_only = False
|
||||
continue
|
||||
|
||||
if p.name.value in param_names:
|
||||
message = "duplicate argument '%s' in function definition"
|
||||
self.add_issue(p.name, message=message % p.name.value)
|
||||
param_names.add(p.name.value)
|
||||
|
||||
if p.default is None and not p.star_count:
|
||||
if default_only:
|
||||
return True
|
||||
else:
|
||||
default_only = True
|
||||
if not star_seen:
|
||||
if p.default is None and not p.star_count:
|
||||
if default_only:
|
||||
return True
|
||||
elif p.star_count:
|
||||
star_seen = True
|
||||
default_only = False
|
||||
else:
|
||||
default_only = True
|
||||
|
||||
|
||||
@ErrorFinder.register_rule(type='try_stmt')
|
||||
|
||||
@@ -46,6 +46,28 @@ def x(b=a):
|
||||
global a
|
||||
|
||||
|
||||
def x(*args, c=2, d):
|
||||
pass
|
||||
|
||||
|
||||
def x(*, c=2, d):
|
||||
pass
|
||||
|
||||
|
||||
def x(a, b=1, *args, c=2, d):
|
||||
pass
|
||||
|
||||
|
||||
def x(a, b=1, *, c=2, d):
|
||||
pass
|
||||
|
||||
|
||||
lambda *args, c=2, d: (c, d)
|
||||
lambda *, c=2, d: (c, d)
|
||||
lambda a, b=1, *args, c=2, d: (c, d)
|
||||
lambda a, b=1, *, c=2, d: (c, d)
|
||||
|
||||
|
||||
*foo, a = (1,)
|
||||
*foo[0], a = (1,)
|
||||
*[], a = (1,)
|
||||
|
||||
Reference in New Issue
Block a user