mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-10342 Instance attribute defined outside init: detect functions called in init
This commit is contained in:
@@ -67,6 +67,8 @@ public class PyAttributeOutsideInitInspection extends PyInspection {
|
||||
public void visitPyFunction(PyFunction node) {
|
||||
final PyClass containingClass = node.getContainingClass();
|
||||
if (containingClass == null) return;
|
||||
final String name = node.getName();
|
||||
if (name != null && name.startsWith("_")) return;
|
||||
if (!isApplicable(containingClass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
class MyClass(object):
|
||||
def __init__(self):
|
||||
self._resetData()
|
||||
self._val = []
|
||||
|
||||
def _resetData(self):
|
||||
self._val = [] # This should not be receiving a warning. The function gets called in __init__.
|
||||
+4
@@ -66,6 +66,10 @@ public class PyAttributeOutsideInitInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPrivateMethod() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile("inspections/PyAttributeOutsideInitInspection/" + getTestName(true) + ".py");
|
||||
myFixture.enableInspections(PyAttributeOutsideInitInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user