mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 00:40:28 +07:00
PY-76629: Suppress PyProtectedMemberInspection if a member is defined in .pyi
Protected member should not be highlighted as a warning if it resolves to .pyi file. We assume that everything in .pyi file is a public API. GitOrigin-RevId: c8275f3e48e3cd69b1676de9b78606f28ea224c8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
214f894da3
commit
91f27d8587
@@ -20,6 +20,7 @@ import com.jetbrains.python.inspections.PyInspectionExtension
|
||||
import com.jetbrains.python.psi.PyFromImportStatement
|
||||
import com.jetbrains.python.psi.PyImportElement
|
||||
import com.jetbrains.python.psi.PyImportStatement
|
||||
import com.jetbrains.python.psi.PyReferenceExpression
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext
|
||||
|
||||
class PyiInspectionExtension : PyInspectionExtension() {
|
||||
@@ -35,4 +36,9 @@ class PyiInspectionExtension : PyInspectionExtension() {
|
||||
}
|
||||
return elements.isEmpty() || elements.any { it.asName != null }
|
||||
}
|
||||
|
||||
override fun ignoreProtectedSymbol(expression: PyReferenceExpression, context: TypeEvalContext): Boolean {
|
||||
val referencedElement = expression.reference.resolve()
|
||||
return referencedElement?.containingFile is PyiFile
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from test import MyClass
|
||||
|
||||
public_api = MyClass._public_api
|
||||
not_public_api = <weak_warning descr="Access to a protected member _not_public_api of a class">MyClass._not_public_api</weak_warning>
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass:
|
||||
def __init__(self):
|
||||
self._public_api = "abacaba"
|
||||
self._not_public_api = "qwerty"
|
||||
@@ -0,0 +1,3 @@
|
||||
class MyClass:
|
||||
def __init__(self) -> None: ...
|
||||
_public_api: str
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.jetbrains.python.pyi;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.idea.TestFor;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
@@ -149,4 +150,7 @@ public class PyiInspectionsTest extends PyTestCase {
|
||||
public void testMissedSuperInitCall() {
|
||||
doPyiTest(PyMissingConstructorInspection.class);
|
||||
}
|
||||
|
||||
@TestFor(issues = "PY-16477")
|
||||
public void testAccessProtectedProperty() { doPyTest(PyProtectedMemberInspection.class); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user