diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java index 3f7bb6cf8017..8a16de90920e 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java @@ -235,7 +235,18 @@ public class PyCallExpressionHelper { boolean isByClass ) { int implicit_offset = 0; - if (isByInstance || isConstructorCall) implicit_offset += 1; + boolean firstIsArgsOrKwargs = false; + final PyParameter[] parameters = callable.getParameterList().getParameters(); + if (parameters.length > 0) { + final PyParameter first = parameters[0]; + final PyNamedParameter named = first.getAsNamed(); + if (named != null && (named.isPositionalContainer() || named.isKeywordContainer())) { + firstIsArgsOrKwargs = true; + } + } + if (!firstIsArgsOrKwargs && (isByInstance || isConstructorCall)) { + implicit_offset += 1; + } PyFunction method = callable.asMethod(); if (method == null) return implicit_offset; diff --git a/python/testData/inspections/PyArgumentListInspection/args.py b/python/testData/inspections/PyArgumentListInspection/args.py index 8bb554823f0e..d2c12e961c09 100644 --- a/python/testData/inspections/PyArgumentListInspection/args.py +++ b/python/testData/inspections/PyArgumentListInspection/args.py @@ -10,6 +10,7 @@ def test_union_type(): bar = (1,) if True else (1, 2) foo(*bar) #pass + # PY-4890 def test_old_style_iterable(): class C: @@ -22,4 +23,13 @@ def test_old_style_iterable(): pass xs = C() foo(*xs) #pass - foo(*'bar') #pass \ No newline at end of file + foo(*'bar') #pass + + +# PY-6108 +def test_unexpected_args_without_self(): + class C: + def sm(*args, **kwargs): + return args, kwargs + x = C() + x.sm(1, 2, 3) #pass