PY-24817 Fixed: False positive: Method may be 'static' when docstring is present

Update PyMethodMayBeStaticInspection to consider more methods as empty ones.
This commit is contained in:
Semyon Proshev
2017-07-05 20:14:23 +03:00
committed by Semyon Proshev
parent cb598c94c5
commit 934f3da2a5
3 changed files with 12 additions and 6 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,10 +78,7 @@ public class PyMethodMayBeStaticInspection extends PyInspection {
if (!attributes.isEmpty()) return;
if (isTestElement(node)) return;
final PyStatementList statementList = node.getStatementList();
final PyStatement[] statements = statementList.getStatements();
if (statements.length == 1 && statements[0] instanceof PyPassStatement) return;
if (PyUtil.isEmptyFunction(node)) return;
final PyParameter[] parameters = node.getParameterList().getParameters();
@@ -0,0 +1,4 @@
class A:
def foo(self):
"""Do something"""
pass
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,6 +105,11 @@ public class PyMethodMayBeStaticInspectionTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON30, () -> doTest());
}
// PY-24817
public void testDocumentedEmpty() {
doTest();
}
private void doTest() {
myFixture.configureByFile(getTestName(true) + ".py");
myFixture.enableInspections(PyMethodMayBeStaticInspection.class);