PY-34493 Enable back copying annotations from third-party .py files on Override/Implement

Since disabling turned out to be controversial. Even in the ticket some users were
against this decision claiming that it heavily annotated code bases it might be necessary
to retain all annotations from inherited method signatures. We need to think of a better
solution for controlling this behavior on case-to-case basis.

GitOrigin-RevId: c68763f0cad23de8975085e9bc8a6fd99013de3b
This commit is contained in:
Mikhail Golubev
2023-08-09 20:53:35 +00:00
committed by intellij-monorepo-bot
parent a2af264b63
commit 63d24cbb9d
10 changed files with 10 additions and 15 deletions
@@ -351,7 +351,7 @@ public abstract class PythonCommonCompletionTest extends PythonCommonTestCase {
}
// PY-34493
public void testSuperMethodAnnotationsNotCopiedFromThirdPartyLibrary() {
public void testSuperMethodAnnotationsCopiedFromThirdPartyLibrary() {
runWithLanguageLevel(LanguageLevel.getLatest(), () -> {
runWithAdditionalClassEntryInSdkRoots(getTestName(true) + "/lib", () -> {
myFixture.copyDirectoryToProject(getTestName(true) + "/src", "");
@@ -10,7 +10,6 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.light.LightElement;
import com.intellij.psi.search.ProjectScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.psi.util.QualifiedName;
@@ -389,11 +388,7 @@ public final class PyPsiRefactoringUtil {
}
public static boolean shouldCopyAnnotations(@NotNull PsiElement copiedElement, @NotNull PsiFile destFile) {
if (LanguageLevel.forElement(copiedElement).isPython2() ||
(PyiUtil.isInsideStub(copiedElement) && !PyiUtil.isPyiFileOfPackage(destFile))) {
return false;
}
VirtualFile virtualFile = copiedElement.getContainingFile().getVirtualFile();
return virtualFile != null && ProjectScope.getProjectScope(copiedElement.getProject()).contains(virtualFile);
return !LanguageLevel.forElement(copiedElement).isPython2() &&
(!PyiUtil.isInsideStub(copiedElement) || PyiUtil.isPyiFileOfPackage(destFile));
}
}
@@ -0,0 +1,5 @@
from mod import Super
class Sub(Super):
def method(self, x: int) -> str:<caret>
@@ -1,5 +0,0 @@
from mod import Super
class Sub(Super):
def method(self, x):<caret>
@@ -2,5 +2,5 @@ from lib import Base
class Sub(Base):
def method(self, x):
def method(self, x: int) -> str:
return super().method(x)
@@ -235,7 +235,7 @@ public class PyOverrideTest extends PyTestCase {
}
// PY-34493
public void testAnnotationsNotCopiedFromThirdPartyLibraries() {
public void testAnnotationsAreCopiedFromThirdPartyLibraries() {
runWithAdditionalClassEntryInSdkRoots(getTestName(false) + "/lib", () -> {
myFixture.copyDirectoryToProject(getTestName(false) + "/src", "");
myFixture.configureByFile("main.py");