mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed overriding instance and subclass checks for types (PY-10229)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user