Only apply non-default params logic prior to the star (fixes #161)

This commit is contained in:
Bryan Forbes
2021-02-15 19:20:43 -06:00
parent 93206f6eba
commit e5731d3932
3 changed files with 40 additions and 6 deletions

View File

@@ -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)

View File

@@ -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,15 +942,26 @@ 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 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

View File

@@ -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,)