From 5c4eb9b77245269c82685ceb2a7bf9fbccadb906 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Mon, 3 Jun 2019 20:09:12 +0300 Subject: [PATCH] Fix determining if there is installed package for some third-party stub in typeshed (PEP 591) (PY-34945) Previously `typing_extensions.pyi` had not been considered as stub because pypi package is called `typing-extensions` GitOrigin-RevId: a72abc97248b641a901a70213d6be410324d3322 --- .../python/codeInsight/typing/PyTypeShed.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/typing/PyTypeShed.kt b/python/src/com/jetbrains/python/codeInsight/typing/PyTypeShed.kt index fb8179552ce4..5c8abf94105c 100644 --- a/python/src/com/jetbrains/python/codeInsight/typing/PyTypeShed.kt +++ b/python/src/com/jetbrains/python/codeInsight/typing/PyTypeShed.kt @@ -52,11 +52,14 @@ object PyTypeShed { if (ApplicationManager.getApplication().isUnitTestMode) { return true } - val topLevelPackage = name.firstComponent ?: return false - val pyPIPackages = PyPIPackageUtil.PACKAGES_TOPLEVEL[topLevelPackage] ?: emptyList() - val packages = PyPackageManagers.getInstance().forSdk(sdk).packages ?: return true - return PyPackageUtil.findPackage(packages, topLevelPackage) != null || - pyPIPackages.any { PyPackageUtil.findPackage(packages, it) != null } + val possiblePackage = name.firstComponent ?: return false + val alternativePossiblePackages = PyPIPackageUtil.PACKAGES_TOPLEVEL[possiblePackage] ?: emptyList() + + val packageManager = PyPackageManagers.getInstance().forSdk(sdk) + val installedPackages = packageManager.packages ?: return true + + return packageManager.parseRequirement(possiblePackage)?.match(installedPackages) != null || + alternativePossiblePackages.any { PyPackageUtil.findPackage(installedPackages, it) != null } } return false }