mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-9407 Method can be static: false positive for methods with first parameter other then self
This commit is contained in:
@@ -65,12 +65,23 @@ public class PyMethodMayBeStaticInspection extends PyInspection {
|
||||
|
||||
if (statements.length == 1 && statements[0] instanceof PyPassStatement) return;
|
||||
|
||||
final PyParameter[] parameters = node.getParameterList().getParameters();
|
||||
|
||||
final String selfName;
|
||||
if (parameters.length > 0) {
|
||||
final String name = parameters[0].getName();
|
||||
selfName = name != null ? name : parameters[0].getText();
|
||||
}
|
||||
else {
|
||||
selfName = PyNames.CANONICAL_SELF;
|
||||
}
|
||||
|
||||
final boolean[] mayBeStatic = {true};
|
||||
PyRecursiveElementVisitor visitor = new PyRecursiveElementVisitor() {
|
||||
@Override
|
||||
public void visitPyReferenceExpression(PyReferenceExpression node) {
|
||||
super.visitPyReferenceExpression(node);
|
||||
if (PyNames.CANONICAL_SELF.equals(node.getName())) {
|
||||
if (selfName.equals(node.getName())) {
|
||||
mayBeStatic[0] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
|
||||
class A():
|
||||
def my_method(my_inst):
|
||||
my_inst.do_smth()
|
||||
@@ -39,6 +39,10 @@ public class PyMethodMayBeStaticInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSelfName() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile("inspections/PyMethodMayBeStaticInspection/" + getTestName(true) + ".py");
|
||||
myFixture.enableInspections(PyMethodMayBeStaticInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user