Fixed false positive for arguments passed to class method without explicit 'self' (PY-6108)

This commit is contained in:
Andrey Vlasovskikh
2012-04-03 17:24:06 +04:00
parent 882f18780c
commit 72c061d304
2 changed files with 23 additions and 2 deletions
@@ -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;
@@ -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
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