Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2012-08-07 20:34:30 +02:00
4 changed files with 124 additions and 101 deletions
@@ -63,93 +63,29 @@ public class PyParameterListImpl extends PyBaseElementImpl<PyParameterListStub>
return false;
}
public boolean isCompatibleTo(@NotNull PyParameterList another) {
PyParameter[] parameters = getParameters();
final PyParameter[] anotherParameters = another.getParameters();
final int parametersLength = parameters.length;
final int anotherParametersLength = anotherParameters.length;
if (parametersLength == anotherParametersLength) {
if (hasPositionalContainer() == another.hasPositionalContainer() && hasKeywordContainer() == another.hasKeywordContainer()) {
return true;
}
public boolean isCompatibleTo(@NotNull PyParameterList other) {
PyParameter[] params = getParameters();
final PyParameter[] otherParams = other.getParameters();
if (hasPositionalContainer() || hasKeywordContainer()) {
return true;
}
int i = 0;
int j = 0;
while (i < parametersLength && j < anotherParametersLength) {
PyParameter parameter = parameters[i];
PyParameter anotherParameter = anotherParameters[j];
if (parameter instanceof PyNamedParameter && anotherParameter instanceof PyNamedParameter) {
PyNamedParameter namedParameter = (PyNamedParameter)parameter;
PyNamedParameter anotherNamedParameter = (PyNamedParameter)anotherParameter;
if (namedParameter.isPositionalContainer()) {
while (j < anotherParametersLength
&& !anotherNamedParameter.isPositionalContainer()
&& !anotherNamedParameter.isKeywordContainer()) {
anotherParameter = anotherParameters[j++];
anotherNamedParameter = (PyNamedParameter) anotherParameter;
}
++i;
continue;
}
if (anotherNamedParameter.isPositionalContainer()) {
while (i < parametersLength
&& !namedParameter.isPositionalContainer()
&& !namedParameter.isKeywordContainer()) {
parameter = parameters[i++];
namedParameter = (PyNamedParameter) parameter;
}
++j;
continue;
}
if (namedParameter.isKeywordContainer() || anotherNamedParameter.isKeywordContainer()) {
break;
}
final PyFunction otherFunction = other.getContainingFunction();
final boolean otherHasArgs = other.hasPositionalContainer();
final boolean otherHasKwargs = other.hasKeywordContainer();
if (otherHasArgs || otherHasKwargs) {
int specialParamsCount = 0;
if (otherHasArgs) {
specialParamsCount++;
}
// both are simple parameters
++i;
++j;
}
if (i < parametersLength) {
if (parameters[i] instanceof PyNamedParameter) {
final PyNamedParameter nextParameter = (PyNamedParameter)parameters[i];
if (nextParameter.isKeywordContainer() || nextParameter.isPositionalContainer()) {
++i;
}
while (nextParameter.isKeywordContainer() && j<anotherParametersLength && anotherParameters[j].hasDefaultValue()) {
j++;
}
if (otherHasKwargs) {
specialParamsCount++;
}
}
if (j < anotherParametersLength) {
if (anotherParameters[j] instanceof PyNamedParameter) {
final PyNamedParameter nextParameter = (PyNamedParameter)anotherParameters[j];
if (nextParameter.isKeywordContainer() || nextParameter.isPositionalContainer()) {
++j;
}
while (nextParameter.isKeywordContainer() && i<parametersLength && parameters[i].hasDefaultValue()) {
i++;
}
if (otherFunction != null && otherFunction.asMethod() != null) {
specialParamsCount++;
}
return otherParams.length == specialParamsCount;
}
return (i >= parametersLength) && (j >= anotherParametersLength);
//
//if (weHaveStarred && parameters.length - 1 <= anotherParameters.length) {
// if (weHaveDoubleStarred == anotherHasDoubleStarred) {
// return true;
// }
//}
//if ((anotherHasDoubleStarred && parameters.length == anotherParameters.length - 1)
// || (weHaveDoubleStarred && parameters.length == anotherParameters.length + 1)) {
// return true;
//}
//return false;
return params.length == otherParams.length;
}
@Override
@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>method-overriding.py</file>
<line>10</line>
<description>Method signature does not match signature of base method</description>
</problem>
<problem>
<file>method-overriding.py</file>
<line>14</line>
<description>Method signature does not match signature of base method</description>
</problem>
<problem>
<file>method-overriding.py</file>
<line>46</line>
<description>Method signature does not match signature of base method</description>
</problem>
</problems>
@@ -0,0 +1,105 @@
class c1:
def foo(self, a):
pass
class c2(c1):
def foo(self, *a):
pass
class c3(c1):
def foo<warning descr="Method signature does not match signature of base method">(self)</warning>:
pass
class c4(c1):
def foo(self, **a):
pass
class c5(c1):
def foo(self, a):
pass
class c6:
pass
class c7(c6):
def foo(self):
pass
class c8:
def __init__(self):
pass
def __new__(self):
pass
def foo(self, a):
pass
class c9(c8):
def __init__(self, a): # different but ok because __init__ is special
pass
def __new__(self, p, q): # different but ok because __new__ is special
pass
def foo<warning descr="Method signature does not match signature of base method">(self, s, t)</warning>:
pass
class c10:
def foo(self, a, b):
pass
class c11(c10):
def foo(self, *b):
pass
class c12(c4):
def foo(self):
pass
class c13:
def foo(self, *args):
pass
class c14(c13):
def foo(self):
pass
class c15: # PY-1083
def foo(self, x = 1):
pass
class c16:
def foo(self, **kwargs):
pass
# PY-6700
class c17:
def foo(self, **kwargs):
pass
class c18(c17):
def foo(self, arg1=None, **kwargs): # pass
pass
class c19:
def foo(self, *args, **kwargs):
raise NotImplementedError()
class c20(c19):
def foo(self): # pass
pass
class c21(c19):
def foo(self, arg1): # pass
pass
class c22:
def foo(self, arg1, *args, **kwargs):
raise NotImplementedError()
class c23(c22):
def foo<warning descr="Method signature does not match signature of base method">(self, arg1, arg2=None)</warning>: # fail
pass
@@ -70,7 +70,7 @@ public class PythonInspectionsTest extends PyTestCase {
public void testPyMethodOverridingInspection() {
LocalInspectionTool inspection = new PyMethodOverridingInspection();
doTest(getTestName(false), inspection);
doHighlightingTest(inspection);
}
public void testPyTrailingSemicolonInspection() {