mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
PY-73107 Usages of @warnings.deprecated inside .pyi stubs are ignored
GitOrigin-RevId: 7682eff8c8ca8ae8241ddee3191add34ab2ac22e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
84243e4280
commit
f2a322c6d9
@@ -12,11 +12,10 @@ fun extractDeprecationMessageFromDecorator(element: PyAstDecoratable): String? {
|
||||
return null
|
||||
}
|
||||
|
||||
val argumentList = deprecatedDecorator.argumentList ?: return null
|
||||
|
||||
if (argumentList.arguments.isEmpty()) {
|
||||
if (deprecatedDecorator.arguments.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
val argument = argumentList.arguments[0] as? PyAstStringLiteralExpression ?: return null
|
||||
|
||||
val argument = deprecatedDecorator.arguments[0] as? PyAstStringLiteralExpression ?: return null
|
||||
return argument.stringValue
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.jetbrains.python.PyPsiBundle;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.PyKnownDecoratorUtil.KnownDecorator;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import com.jetbrains.python.pyi.PyiFile;
|
||||
import com.jetbrains.python.pyi.PyiUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -75,6 +76,13 @@ public final class PyDeprecationInspection extends PyInspection {
|
||||
@NlsSafe String deprecationMessage = null;
|
||||
if (resolveResult instanceof PyDeprecatable deprecatable) {
|
||||
deprecationMessage = deprecatable.getDeprecationMessage();
|
||||
|
||||
if (deprecationMessage == null && !(resolveResult.getContainingFile() instanceof PyiFile)) {
|
||||
PsiElement stub = PyiUtil.getPythonStub((PyElement)deprecatable);
|
||||
if (stub instanceof PyDeprecatable stubDeprecatable) {
|
||||
deprecationMessage = stubDeprecatable.getDeprecationMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (resolveResult instanceof PyFile) {
|
||||
deprecationMessage = ((PyFile)resolveResult).getDeprecationMessage();
|
||||
|
||||
2
python/testData/deprecation/deprecatedLibrary.py
Normal file
2
python/testData/deprecation/deprecatedLibrary.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def my_method(x: int) -> int:
|
||||
return 0
|
||||
5
python/testData/deprecation/deprecatedLibrary.pyi
Normal file
5
python/testData/deprecation/deprecatedLibrary.pyi
Normal file
@@ -0,0 +1,5 @@
|
||||
from typing_extensions import deprecated
|
||||
|
||||
|
||||
@deprecated("deprecated method")
|
||||
def my_method(x: int) -> int: ...
|
||||
3
python/testData/deprecation/usingDeprecatedMethod.py
Normal file
3
python/testData/deprecation/usingDeprecatedMethod.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from deprecatedLibrary import my_method
|
||||
|
||||
<warning descr="deprecated method">my_method</warning>(10)
|
||||
@@ -114,6 +114,12 @@ public class PyDeprecationTest extends PyTestCase {
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
public void testStubAndPyFile() {
|
||||
myFixture.enableInspections(PyDeprecationInspection.class);
|
||||
myFixture.configureByFiles("deprecation/usingDeprecatedMethod.py", "deprecation/deprecatedLibrary.py", "deprecation/deprecatedLibrary.pyi");
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
public void testCustomDeprecatedAnnotation() {
|
||||
myFixture.enableInspections(PyDeprecationInspection.class);
|
||||
myFixture.configureByFile("deprecation/customDeprecatedAnnotation.py");
|
||||
|
||||
Reference in New Issue
Block a user