Fixed overriding instance and subclass checks for types (PY-10229)

This commit is contained in:
Andrey Vlasovskikh
2013-09-13 18:03:20 +04:00
parent dce5c8e936
commit 79395feed7
4 changed files with 17 additions and 1 deletions
@@ -220,7 +220,9 @@ public class PyOverrideImplementUtil {
statementBody.append("(");
final LanguageLevel langLevel = ((PyFile)pyClass.getContainingFile()).getLanguageLevel();
if (!langLevel.isPy3K()) {
statementBody.append(pyClass.getName()).append(", ").append(PyUtil.getFirstParameterName(baseFunction));
final String baseFirstName = !baseParams.isEmpty() ? baseParams.get(0).getName() : null;
final String firstName = baseFirstName != null ? baseFirstName : PyNames.CANONICAL_SELF;
statementBody.append(pyClass.getName()).append(", ").append(firstName);
}
statementBody.append(").").append(baseFunction.getName()).append("(");
if (parameters.size() > 0) {
@@ -0,0 +1,2 @@
class MyType(type):
<caret>pass
@@ -0,0 +1,3 @@
class MyType(type):
def __instancecheck__(cls, instance):
<selection>return super(MyType, cls).__instancecheck__(instance)</selection>
@@ -97,4 +97,13 @@ public class PyOverrideTest extends PyTestCase {
public void testKwargs() { // PY-7401
doTest3k();
}
// PY-10229
public void testInstanceCheck() {
myFixture.configureByFile("override/" + getTestName(true) + ".py");
final PyClass cls = getTopLevelClass(0);
final PyFunction method = cls.findMethodByName("__instancecheck__", true);
PyOverrideImplementUtil.overrideMethods(myFixture.getEditor(), cls, Collections.singletonList(new PyMethodMember(method)));
myFixture.checkResultByFile("override/" + getTestName(true) + "_after.py", true);
}
}