diff --git a/python/src/com/jetbrains/python/inspections/PyAttributeOutsideInitInspection.java b/python/src/com/jetbrains/python/inspections/PyAttributeOutsideInitInspection.java index 791a1b52d38b..76d6a40323cf 100644 --- a/python/src/com/jetbrains/python/inspections/PyAttributeOutsideInitInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyAttributeOutsideInitInspection.java @@ -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; } diff --git a/python/testData/inspections/PyAttributeOutsideInitInspection/privateMethod.py b/python/testData/inspections/PyAttributeOutsideInitInspection/privateMethod.py new file mode 100644 index 000000000000..53034260511b --- /dev/null +++ b/python/testData/inspections/PyAttributeOutsideInitInspection/privateMethod.py @@ -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__. \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyAttributeOutsideInitInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyAttributeOutsideInitInspectionTest.java index 7c8812f44f97..de041b8a550f 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyAttributeOutsideInitInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyAttributeOutsideInitInspectionTest.java @@ -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);