mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Don't show warnings for unused imports listed in __all__ (PY-2668)
This commit is contained in:
@@ -715,9 +715,14 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
Set<PyImportStatementBase> unusedStatements = new HashSet<PyImportStatementBase>();
|
||||
final PyUnresolvedReferencesInspection suppressableInspection = new PyUnresolvedReferencesInspection();
|
||||
PyQualifiedName packageQName = null;
|
||||
List<String> dunderAll = null;
|
||||
|
||||
for (NameDefiner unusedImport : unusedImports) {
|
||||
if (packageQName == null) {
|
||||
final PsiFile file = unusedImport.getContainingFile();
|
||||
if (file instanceof PyFile) {
|
||||
dunderAll = ((PyFile)file).getDunderAll();
|
||||
}
|
||||
if (file != null && PyUtil.isPackage(file)) {
|
||||
packageQName = ResolveImportUtil.findShortestImportableQName(file);
|
||||
}
|
||||
@@ -745,10 +750,14 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
}
|
||||
PsiFileSystemItem importedElement;
|
||||
if (unusedImport instanceof PyImportElement) {
|
||||
final PsiElement element = ResolveImportUtil.resolveImportElement((PyImportElement)unusedImport);
|
||||
final PyImportElement importElement = (PyImportElement)unusedImport;
|
||||
final PsiElement element = ResolveImportUtil.resolveImportElement(importElement);
|
||||
if (element == null) {
|
||||
continue;
|
||||
}
|
||||
if (dunderAll != null && dunderAll.contains(importElement.getVisibleName())) {
|
||||
continue;
|
||||
}
|
||||
importedElement = element.getContainingFile();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from .m1 import f
|
||||
from p1.m1 import f
|
||||
from m1 import f
|
||||
<warning descr="Unused import statement">from a import g, h</warning>
|
||||
from a import g
|
||||
<warning descr="Unused import statement">from a import h</warning>
|
||||
|
||||
__all__ = ['f', 'g']
|
||||
|
||||
Reference in New Issue
Block a user