mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
#PY-14614 fixed Add option to ignore PyProtectedMemberInspection in type annotations
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
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.codeInsight.controlflow.ScopeOwner;
|
||||
@@ -55,6 +56,7 @@ import java.util.List;
|
||||
*/
|
||||
public class PyProtectedMemberInspection extends PyInspection {
|
||||
public boolean ignoreTestFunctions = true;
|
||||
public boolean ignoreAnnotations = false;
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@@ -90,6 +92,7 @@ public class PyProtectedMemberInspection extends PyInspection {
|
||||
@Override
|
||||
public void visitPyReferenceExpression(PyReferenceExpression node) {
|
||||
final PyExpression qualifier = node.getQualifier();
|
||||
if (ignoreAnnotations && PsiTreeUtil.getParentOfType(node, PyAnnotation.class) != null) return;
|
||||
if (qualifier == null || PyNames.CANONICAL_SELF.equals(qualifier.getText())) return;
|
||||
checkReference(node, qualifier);
|
||||
}
|
||||
@@ -102,7 +105,6 @@ public class PyProtectedMemberInspection extends PyInspection {
|
||||
|
||||
if (name != null && name.startsWith("_") && !name.startsWith("__") && !name.endsWith("__")) {
|
||||
final PsiReference reference = node.getReference(getResolveContext());
|
||||
if (reference == null) return;
|
||||
for (final PyInspectionExtension inspectionExtension : PyInspectionExtension.EP_NAME.getExtensions()) {
|
||||
if (inspectionExtension.ignoreProtectedSymbol(node, myTypeEvalContext)) {
|
||||
return;
|
||||
@@ -161,6 +163,7 @@ public class PyProtectedMemberInspection extends PyInspection {
|
||||
public JComponent createOptionsPanel() {
|
||||
MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this);
|
||||
panel.addCheckbox("Ignore test functions", "ignoreTestFunctions");
|
||||
panel.addCheckbox("Ignore annotations", "ignoreAnnotations");
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class A:
|
||||
pass
|
||||
|
||||
A._inner = 10
|
||||
def id(a: A._inner):
|
||||
return a
|
||||
@@ -17,6 +17,7 @@ package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
|
||||
/**
|
||||
* User: ktisha
|
||||
@@ -60,6 +61,14 @@ public class PyProtectedMemberInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnnotation() {
|
||||
setLanguageLevel(LanguageLevel.PYTHON34);
|
||||
PyProtectedMemberInspection inspection = new PyProtectedMemberInspection();
|
||||
inspection.ignoreAnnotations = true;
|
||||
myFixture.configureByFile(getTestName(true) + ".py");
|
||||
myFixture.checkHighlighting(false, false, true);
|
||||
}
|
||||
|
||||
public void testModule() {
|
||||
myFixture.configureByFiles(getTestName(true) + ".py", "tmp.py");
|
||||
myFixture.enableInspections(PyProtectedMemberInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user