mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Do not suggest stub package if it exists locally and resolves (PY-31740)
This commit is contained in:
@@ -170,7 +170,7 @@ private fun isUserFile(element: PsiElement, module: Module?) =
|
||||
/**
|
||||
* See [findStubPackage] and [transferStubPackageMarker].
|
||||
*/
|
||||
private fun isInStubPackage(element: PsiElement) = element.getUserData(STUB_PACKAGE_KEY) == true
|
||||
fun isInStubPackage(element: PsiElement) = element.getUserData(STUB_PACKAGE_KEY) == true
|
||||
|
||||
private fun isInTypeShed(element: PsiElement) =
|
||||
pyi(element) && (element as? PsiFileSystemItem)?.virtualFile.let { it != null && PyTypeShed.isInside(it) }
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.jetbrains.python.packaging.requirement.PyRequirementRelation
|
||||
import com.jetbrains.python.psi.PyFile
|
||||
import com.jetbrains.python.psi.PyFromImportStatement
|
||||
import com.jetbrains.python.psi.PyImportElement
|
||||
import com.jetbrains.python.psi.PyReferenceExpression
|
||||
import com.jetbrains.python.sdk.PythonSdkType
|
||||
import javax.swing.JComponent
|
||||
|
||||
@@ -69,16 +70,23 @@ class PyStubPackagesAdvertiser : PyInspection() {
|
||||
|
||||
override fun visitPyFromImportStatement(node: PyFromImportStatement) {
|
||||
super.visitPyFromImportStatement(node)
|
||||
processQName(node.importSourceQName)
|
||||
processImport(node.importSource, node.importSourceQName)
|
||||
}
|
||||
|
||||
override fun visitPyImportElement(node: PyImportElement) {
|
||||
super.visitPyImportElement(node)
|
||||
processQName(node.importedQName)
|
||||
processImport(node.importReferenceExpression, node.importedQName)
|
||||
}
|
||||
|
||||
private fun processQName(qualifiedName: QualifiedName?) {
|
||||
qualifiedName?.firstComponent?.let(sources::add)
|
||||
private fun processImport(ref: PyReferenceExpression?, qName: QualifiedName?) {
|
||||
if (qName == null) return
|
||||
|
||||
if (ref != null &&
|
||||
ref.getReference(resolveContext).multiResolve(false).asSequence().mapNotNull { it.element }.any { isInStubPackage(it) }) {
|
||||
return
|
||||
}
|
||||
|
||||
qName.firstComponent?.let(sources::add)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,9 +205,9 @@ class PyStubPackagesAdvertiser : PyInspection() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun whiteListedSourcesToProcess(sources: Set<String>): Set<String> = sources.filterTo(mutableSetOf()) { it in WHITE_LIST }
|
||||
private fun whiteListedSourcesToProcess(sources: Set<String>) = sources.filterTo(mutableSetOf()) { it in WHITE_LIST }
|
||||
|
||||
private fun notWhiteListedSourcesToProcess(sources: Set<String>): Set<String> = sources.filterNotTo(mutableSetOf()) { it in WHITE_LIST }
|
||||
private fun notWhiteListedSourcesToProcess(sources: Set<String>) = sources.filterNotTo(mutableSetOf()) { it in WHITE_LIST }
|
||||
|
||||
private fun splitIntoNotCachedAndCached(sources: Set<String>,
|
||||
cache: Cache<String, Set<RepoPackage>>): Pair<Set<String>, Set<RepoPackage>> {
|
||||
|
||||
Reference in New Issue
Block a user