From f0e9deabf0bb14d038fbedc949b14abe2c9fb2ca Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Fri, 26 Jul 2013 13:55:51 +0400 Subject: [PATCH] fixed PY-10296 Access to protected member should have different severity levels --- .../python/inspections/PyProtectedMemberInspection.java | 3 ++- .../inspections/PyProtectedMemberInspection/selfField.py | 3 +++ .../python/inspections/PyProtectedMemberInspectionTest.java | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 python/testData/inspections/PyProtectedMemberInspection/selfField.py diff --git a/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java b/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java index 274edce784a8..921e2fc68559 100644 --- a/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java @@ -7,6 +7,7 @@ import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiReference; import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.python.PyBundle; +import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.PyReferenceExpression; @@ -46,7 +47,7 @@ public class PyProtectedMemberInspection extends PyInspection { @Override public void visitPyReferenceExpression(PyReferenceExpression node) { final PyExpression qualifier = node.getQualifier(); - if (qualifier == null) return; + if (qualifier == null || PyNames.CANONICAL_SELF.equals(qualifier.getText())) return; final String name = node.getName(); if (name != null && name.startsWith("_") && !name.startsWith("__") && !name.endsWith("__")) { final PyClass parentClass = PsiTreeUtil.getParentOfType(node, PyClass.class); diff --git a/python/testData/inspections/PyProtectedMemberInspection/selfField.py b/python/testData/inspections/PyProtectedMemberInspection/selfField.py new file mode 100644 index 000000000000..5d3a5edebd20 --- /dev/null +++ b/python/testData/inspections/PyProtectedMemberInspection/selfField.py @@ -0,0 +1,3 @@ +class B: + def __call__(self, event): + self._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 e3cf6b608d21..60e72a3f92e7 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java @@ -27,6 +27,10 @@ public class PyProtectedMemberInspectionTest extends PyTestCase { doTest(); } + public void testSelfField() { + doTest(); + } + private void doTest() { myFixture.configureByFile("inspections/PyProtectedMemberInspection/" + getTestName(true) + ".py"); myFixture.enableInspections(PyProtectedMemberInspection.class);