mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-19137: Move object to parent in superclass extracting even for Py3K if class explicitly extends object
This commit is contained in:
+8
-1
@@ -44,6 +44,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -79,7 +80,7 @@ public final class PyExtractSuperclassHelper {
|
||||
|
||||
// PY-12171
|
||||
final PyMemberInfo<PyElement> objectMember = MembersManager.findMember(selectedMemberInfos, ALLOW_OBJECT);
|
||||
if (LanguageLevel.forElement(clazz).isPy3K()) {
|
||||
if (LanguageLevel.forElement(clazz).isPy3K() && !isObjectParentDeclaredExplicitly(clazz)) {
|
||||
// Remove object from list if Py3
|
||||
if (objectMember != null) {
|
||||
selectedMemberInfos.remove(objectMember);
|
||||
@@ -110,7 +111,13 @@ public final class PyExtractSuperclassHelper {
|
||||
afterData.addElement(newClass);
|
||||
project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC)
|
||||
.refactoringDone(getRefactoringId(), afterData);
|
||||
}
|
||||
|
||||
/**
|
||||
* If class explicitly extends object we shall move it even in Py3K
|
||||
*/
|
||||
private static boolean isObjectParentDeclaredExplicitly(@NotNull final PyClass clazz) {
|
||||
return Arrays.stream(clazz.getSuperClassExpressions()).filter(o -> PyNames.OBJECT.equals(o.getName())).findFirst().isPresent();
|
||||
}
|
||||
|
||||
private static PyClass placeNewClass(final Project project, PyClass newClass, @NotNull final PyClass clazz, final String targetFile) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Parent(object):
|
||||
def spam(self):
|
||||
pass
|
||||
|
||||
|
||||
class Child(Parent):
|
||||
pass
|
||||
@@ -0,0 +1,3 @@
|
||||
class Child(object):
|
||||
def spam(self):
|
||||
pass
|
||||
+6
@@ -44,6 +44,12 @@ public class PyExtractSuperclassTest extends PyClassRefactoringTest {
|
||||
super("extractsuperclass");
|
||||
}
|
||||
|
||||
// Checks if class explicitly extends object we shall move it even in Py3K (PY-19137)
|
||||
public void testPy3ParentHasObject() throws Exception {
|
||||
setLanguageLevel(LanguageLevel.PYTHON30);
|
||||
doSimpleTest("Child", "Parent", null, true, false, ".spam");
|
||||
}
|
||||
|
||||
// Checks that moving methods between files moves imports as well
|
||||
public void testImportMultiFile() throws Throwable {
|
||||
multiFileTestHelper(".do_useful_stuff", false);
|
||||
|
||||
Reference in New Issue
Block a user