PY-11106 Wrong error message: "accessing protected member of class" for module._membe...
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Wed, 16 Oct 2013 11:56:46 +0000 (13:56 +0200)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Wed, 16 Oct 2013 11:56:46 +0000 (13:56 +0200)
python/src/com/jetbrains/python/PyBundle.properties
python/src/com/jetbrains/python/inspections/PyProtectedMemberInspection.java
python/testData/inspections/PyProtectedMemberInspection/module.py [new file with mode: 0644]
python/testData/inspections/PyProtectedMemberInspection/tmp.py [new file with mode: 0644]
python/testSrc/com/jetbrains/python/inspections/PyProtectedMemberInspectionTest.java

index 2191c0c7dbe3c086cb35a862dfec562934dd00c7..5ee3ef7d582e152f02c809fb0d789c22eeee4596 100644 (file)
@@ -458,6 +458,7 @@ INSP.attribute.$0.outside.init=Instance attribute {0} defined outside __init__
 # PyProtectedMemberInspection
 INSP.NAME.protected.member.access=Access to a protected member of a class
 INSP.protected.member.$0.access=Access to a protected member {0} of a class
+INSP.protected.member.$0.access.module=Access to a protected member {0} of a module
 
 # PyArgumentEqualDefaultInspection
 INSP.NAME.argument.equal.default=Argument passed to function is equal to default parameter value
index 921e2fc68559efff4da369d89f569797d83a4ce5..b48ff68112f9de5d253ecd225b45ee9eb5e38041 100644 (file)
@@ -11,6 +11,8 @@ import com.jetbrains.python.PyNames;
 import com.jetbrains.python.psi.PyClass;
 import com.jetbrains.python.psi.PyExpression;
 import com.jetbrains.python.psi.PyReferenceExpression;
+import com.jetbrains.python.psi.types.PyModuleType;
+import com.jetbrains.python.psi.types.PyType;
 import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -66,7 +68,11 @@ public class PyProtectedMemberInspection extends PyInspection {
             outerClass = PsiTreeUtil.getParentOfType(outerClass, PyClass.class);
           }
         }
-        registerProblem(node, PyBundle.message("INSP.protected.member.$0.access", name));
+        final PyType type = myTypeEvalContext.getType(qualifier);
+        if (type instanceof PyModuleType)
+          registerProblem(node, PyBundle.message("INSP.protected.member.$0.access.module", name));
+        else
+          registerProblem(node, PyBundle.message("INSP.protected.member.$0.access", name));
       }
     }
 
diff --git a/python/testData/inspections/PyProtectedMemberInspection/module.py b/python/testData/inspections/PyProtectedMemberInspection/module.py
new file mode 100644 (file)
index 0000000..891ea99
--- /dev/null
@@ -0,0 +1,3 @@
+import tmp
+
+z = <weak_warning descr="Access to a protected member _test of a module">tmp._test</weak_warning>
\ No newline at end of file
diff --git a/python/testData/inspections/PyProtectedMemberInspection/tmp.py b/python/testData/inspections/PyProtectedMemberInspection/tmp.py
new file mode 100644 (file)
index 0000000..470e961
--- /dev/null
@@ -0,0 +1 @@
+_test = 1
\ No newline at end of file
index 60e72a3f92e778a9cf153cef5b49677aa76a095e..41bff92077ca3744b11a7e85641acc990a3553a2 100644 (file)
@@ -31,9 +31,20 @@ public class PyProtectedMemberInspectionTest extends PyTestCase {
     doTest();
   }
 
+  public void testModule() {
+    myFixture.configureByFiles(getTestName(true) + ".py", "tmp.py");
+    myFixture.enableInspections(PyProtectedMemberInspection.class);
+    myFixture.checkHighlighting(false, false, true);
+  }
+
   private void doTest() {
-    myFixture.configureByFile("inspections/PyProtectedMemberInspection/" + getTestName(true) + ".py");
+    myFixture.configureByFile(getTestName(true) + ".py");
     myFixture.enableInspections(PyProtectedMemberInspection.class);
     myFixture.checkHighlighting(false, false, true);
   }
+
+  @Override
+  protected String getTestDataPath() {
+    return super.getTestDataPath() + "/inspections/PyProtectedMemberInspection/";
+  }
 }