mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix checking if same-package protected module is imported in the inspected one (PY-32485)
It led to false negative when inspected reference resolves to an element in the same file
This commit is contained in:
@@ -82,9 +82,7 @@ public class PyProtectedMemberInspection extends PyInspection {
|
||||
return StreamEx
|
||||
.of(importSource.getReference(resolveContext).multiResolve(false))
|
||||
.map(ResolveResult::getElement)
|
||||
.nonNull()
|
||||
.map(PsiElement::getContainingFile)
|
||||
.nonNull()
|
||||
.select(PyFile.class)
|
||||
.map(PsiFile::getContainingDirectory)
|
||||
.nonNull()
|
||||
.map(PsiDirectory::getVirtualFile)
|
||||
|
||||
@@ -94,6 +94,24 @@ public class PyProtectedMemberInspectionTest extends PyInspectionTestCase {
|
||||
doMultiFileTest("my_package/my_subpackage/module2.py");
|
||||
}
|
||||
|
||||
// PY-32485
|
||||
public void testProtectedMemberOfSameFileClass() {
|
||||
// created file should be considered as located inside a package so Python 3 is used here
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.PYTHON34,
|
||||
() -> doTestByText("class A:\n" +
|
||||
" def __init__(self, arg):\n" +
|
||||
" self._arg = arg\n" +
|
||||
"\n" +
|
||||
" def _f(self):\n" +
|
||||
" return self._arg\n" +
|
||||
"\n" +
|
||||
"a = A(1)\n" +
|
||||
"print(<weak_warning descr=\"Access to a protected member _arg of a class\">a._arg</weak_warning>)\n" +
|
||||
"print(<weak_warning descr=\"Access to a protected member _f of a class\">a._f</weak_warning>())")
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
Reference in New Issue
Block a user