diff --git a/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java b/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java index b516e10d0d78..274edce784a8 100644 --- a/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java @@ -56,6 +56,14 @@ public class PyProtectedMemberInspection extends PyInspection { final PyClass resolvedClass = PsiTreeUtil.getParentOfType(resolvedExpression, PyClass.class); if (parentClass.isSubclass(resolvedClass)) return; + + PyClass outerClass = PsiTreeUtil.getParentOfType(parentClass, PyClass.class); + while (outerClass != null) { + if (outerClass.isSubclass(resolvedClass)) + return; + + outerClass = PsiTreeUtil.getParentOfType(outerClass, PyClass.class); + } } registerProblem(node, PyBundle.message("INSP.protected.member.$0.access", name)); } diff --git a/python/testData/inspections/PyProtectedMemberInspection/outerClass.py b/python/testData/inspections/PyProtectedMemberInspection/outerClass.py new file mode 100644 index 000000000000..efbced59b50f --- /dev/null +++ b/python/testData/inspections/PyProtectedMemberInspection/outerClass.py @@ -0,0 +1,19 @@ + +class AbstractExperimentManager(object): + + def _call_on_plugins(self, method_name, *args, **kwargs): + pass + +class EventExperimentManager(AbstractExperimentManager): + + + class __SomeEvent(object): + + def __init__(self, parent): + """ + :param EventExperimentManager parent: Parent + """ + self.parent = parent + + def __call__(self, event): + self.parent._call_on_plugins("foo") \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java index 9a22725bb4b5..e3cf6b608d21 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java @@ -18,10 +18,15 @@ public class PyProtectedMemberInspectionTest extends PyTestCase { public void testTrueNegative() { doTest(); } + public void testDoubleUnderscore() { doTest(); } + public void testOuterClass() { + doTest(); + } + private void doTest() { myFixture.configureByFile("inspections/PyProtectedMemberInspection/" + getTestName(true) + ".py"); myFixture.enableInspections(PyProtectedMemberInspection.class);