fixed PY-10342 Instance attribute defined outside init: detect functions called in init

This commit is contained in:
Ekaterina Tuzova
2014-03-11 13:26:13 +04:00
parent 4d76bdb5a2
commit f791db7500
3 changed files with 14 additions and 0 deletions
@@ -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__.
@@ -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);