mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-23552 Fixed: PyRedeclaration does not recognize static/class methods
Ignore only functions with unknown or redeclaration decorators in PyRedeclarationInspection
This commit is contained in:
@@ -71,7 +71,8 @@ public class PyRedeclarationInspection extends PyInspection {
|
||||
|
||||
@Override
|
||||
public void visitPyFunction(final PyFunction node) {
|
||||
if (!isDecorated(node)) {
|
||||
if (!PyKnownDecoratorUtil.hasUnknownDecorator(node, myTypeEvalContext) &&
|
||||
!PyKnownDecoratorUtil.hasRedeclarationDecorator(node, myTypeEvalContext)) {
|
||||
processElement(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,10 @@ public class PyKnownDecoratorUtil {
|
||||
return ContainerUtil.exists(getKnownDecorators(function, context), GENERATOR_BASED_COROUTINE_DECORATORS::contains);
|
||||
}
|
||||
|
||||
public static boolean hasRedeclarationDecorator(@NotNull PyFunction function, @NotNull TypeEvalContext context) {
|
||||
return getKnownDecorators(function, context).contains(TYPING_OVERLOAD);
|
||||
}
|
||||
|
||||
private static boolean allDecoratorsAreKnown(@NotNull PyDecoratable element, @NotNull List<KnownDecorator> decorators) {
|
||||
final PyDecoratorList decoratorList = element.getDecoratorList();
|
||||
return decoratorList == null ? decorators.isEmpty() : decoratorList.getDecorators().length == decorators.size();
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class TestClass:
|
||||
@classmethod
|
||||
def foo(cls):
|
||||
print(0)
|
||||
|
||||
@classmethod
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>(cls):
|
||||
print(1)
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class TestClass:
|
||||
def foo(self):
|
||||
print(0)
|
||||
|
||||
@classmethod
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>(cls):
|
||||
print(1)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class TestClass:
|
||||
@staticmethod
|
||||
def foo():
|
||||
print(0)
|
||||
|
||||
@staticmethod
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
print(1)
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class TestClass:
|
||||
def foo(self):
|
||||
print(0)
|
||||
|
||||
@staticmethod
|
||||
def <warning descr="Redeclared 'foo' defined above without usage">foo</warning>():
|
||||
print(1)
|
||||
@@ -104,6 +104,26 @@ public class PyRedeclarationInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-23552
|
||||
public void testStaticMethodRedeclaresInstanceMethod() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-23552
|
||||
public void testClassMethodRedeclaresInstanceMethod() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-23552
|
||||
public void testStaticMethodRedeclaresAnotherStaticMethod() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-23552
|
||||
public void testClassMethodRedeclaresAnotherClassMethod() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "inspections/PyRedeclarationInspection/" + getTestName(true) + ".py";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user