summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-07-10 08:49:19 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-07-10 08:49:19 +0200
commitbc710340c8af251fcacfc9f6de6c7ce56a4b7202 (patch)
tree44f587927e6a1155e47fc76841d405435b681666
parentbe8a2e141d87c6c4fc3e8505d9482837c8d74cf7 (diff)
downloadastroid-git-bc710340c8af251fcacfc9f6de6c7ce56a4b7202.tar.gz
Relax the spreading of defaults to both positional only and positional or keywords arguments
-rw-r--r--astroid/node_classes.py14
-rw-r--r--astroid/tests/unittest_scoped_nodes.py6
2 files changed, 10 insertions, 10 deletions
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
index 8b496032..58f28bcb 100644
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -1626,16 +1626,10 @@ class Arguments(mixins.AssignTypeMixin, NodeNG):
result = []
positional_only_defaults = []
positional_or_keyword_defaults = self.defaults
- if self.defaults and self.args:
- if len(self.defaults) > len(self.args):
- # We have defaults that spread from positional only
- # to positional or keyword parameters.
- # In that case, all the positional or keyword parameters
- # have a default
- positional_or_keyword_defaults = self.defaults[-len(self.args) :]
- positional_only_defaults = self.defaults[
- : len(self.defaults) - len(self.args)
- ]
+ if self.defaults:
+ args = self.args or []
+ positional_or_keyword_defaults = self.defaults[-len(args) :]
+ positional_only_defaults = self.defaults[: len(self.defaults) - len(args)]
if self.posonlyargs:
result.append(_format_args(self.posonlyargs, positional_only_defaults))
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index 87d2fb8e..fca2a90f 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -2044,6 +2044,12 @@ def test_metaclass_cannot_infer_call_yields_an_instance():
pass
"""
),
+ textwrap.dedent(
+ """
+ def __init__(self, other=(), /, **kw):
+ pass
+ """
+ ),
],
)
@test_utils.require_version("3.8")