Correctly calculate qualified name for imported elements (PY-28295)

This commit is contained in:
Semyon Proshev
2018-02-05 20:04:24 +03:00
parent a192424d66
commit a476f44ce7
2 changed files with 18 additions and 2 deletions

View File

@@ -243,7 +243,7 @@ public class PyCompatibilityInspection extends PyInspection {
}
}
final QualifiedName qName = importElement.getImportedQName();
final QualifiedName qName = getImportedFullyQName(importElement);
if (qName != null && !qName.matches("builtins") && !qName.matches("__builtin__")) {
final String moduleName = qName.toString();
@@ -254,6 +254,19 @@ public class PyCompatibilityInspection extends PyInspection {
}
}
@Nullable
private static QualifiedName getImportedFullyQName(@NotNull PyImportElement importElement) {
final QualifiedName importedQName = importElement.getImportedQName();
if (importedQName == null) return null;
final PyStatement containingImportStatement = importElement.getContainingImportStatement();
final QualifiedName importSourceQName = containingImportStatement instanceof PyFromImportStatement
? ((PyFromImportStatement)containingImportStatement).getImportSourceQName()
: null;
return importSourceQName == null ? importedQName : importSourceQName.append(importedQName);
}
@Override
public void visitPyFromImportStatement(PyFromImportStatement node) {
super.visitPyFromImportStatement(node);

View File

@@ -1 +1,4 @@
import <warning descr="Python version 3.4, 3.5, 3.6, 3.7 do not have module Bastion">Bastion</warning>
import <warning descr="Python version 3.4, 3.5, 3.6, 3.7 do not have module Bastion">Bastion</warning>
from <warning descr="Python version 2.6, 2.7 do not have module asyncio">asyncio</warning> import Queue
from io import StringIO