From 891b423d16e1dcac80c626dc7ca49ebe200fabb0 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Thu, 7 Dec 2017 19:40:19 +0300 Subject: [PATCH] Special case `typing` for Python < 3.5 (PY-22945) --- .../jetbrains/python/codeInsight/typing/PyTypeShed.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/typing/PyTypeShed.kt b/python/src/com/jetbrains/python/codeInsight/typing/PyTypeShed.kt index 51b475f3aeaa..a8ca26213707 100644 --- a/python/src/com/jetbrains/python/codeInsight/typing/PyTypeShed.kt +++ b/python/src/com/jetbrains/python/codeInsight/typing/PyTypeShed.kt @@ -23,6 +23,7 @@ import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.util.QualifiedName import com.jetbrains.python.PythonHelpersLocator +import com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider.TYPING import com.jetbrains.python.packaging.PyPIPackageUtil import com.jetbrains.python.packaging.PyPackageManagers import com.jetbrains.python.packaging.PyPackageUtil @@ -40,8 +41,7 @@ import java.io.File object PyTypeShed { private val ONLY_SUPPORTED_PY2_MINOR = 7 private val SUPPORTED_PY3_MINORS = 2..6 - // TODO: Warn about unresolved `import typing` but still resolve it internally for type inference - val WHITE_LIST = setOf("typing", "six", "__builtin__", "builtins", "exceptions", "types", "datetime") + val WHITE_LIST = setOf(TYPING, "six", "__builtin__", "builtins", "exceptions", "types", "datetime") private val BLACK_LIST = setOf() /** @@ -56,7 +56,11 @@ object PyTypeShed { return false } if (isInStandardLibrary(root)) { - return true + if (ApplicationManager.getApplication().isUnitTestMode || + topLevelPackage != TYPING || + PythonSdkType.getLanguageLevelForSdk(sdk).isAtLeast(LanguageLevel.PYTHON35)) { + return true + } } if (isInThirdPartyLibraries(root)) { if (ApplicationManager.getApplication().isUnitTestMode) {