mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-16412 Handle mapping of builtin collections to special types from typing
This commit is contained in:
committed by
Andrey Vlasovskikh
parent
034f409a6a
commit
f27611869f
+12
-4
@@ -19,6 +19,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.jetbrains.python.codeInsight.imports.AddImportHelper;
|
||||
import com.jetbrains.python.codeInsight.imports.AddImportHelper.ImportPriority;
|
||||
import com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyPsiUtils;
|
||||
import com.jetbrains.python.psi.types.*;
|
||||
@@ -293,17 +294,24 @@ public class PyTypeHintGenerationUtil {
|
||||
collectImportTargetsFromType(pyType, classes, names);
|
||||
}
|
||||
}
|
||||
else if (type instanceof PyClassType) {
|
||||
classes.add(((PyClassType)type).getPyClass());
|
||||
}
|
||||
else if (type instanceof PyCollectionType) {
|
||||
if (type instanceof PyCollectionTypeImpl) {
|
||||
classes.add(((PyCollectionTypeImpl)type).getPyClass());
|
||||
final PyClass pyClass = ((PyCollectionTypeImpl)type).getPyClass();
|
||||
final String typingCollectionName = PyTypingTypeProvider.TYPING_COLLECTION_CLASSES.get(pyClass.getQualifiedName());
|
||||
if (typingCollectionName != null && type.isBuiltin()) {
|
||||
names.add(typingCollectionName);
|
||||
}
|
||||
else {
|
||||
classes.add(pyClass);
|
||||
}
|
||||
}
|
||||
for (PyType pyType : ((PyCollectionType)type).getElementTypes()) {
|
||||
collectImportTargetsFromType(pyType, classes, names);
|
||||
}
|
||||
}
|
||||
else if (type instanceof PyClassType) {
|
||||
classes.add(((PyClassType)type).getPyClass());
|
||||
}
|
||||
if (type instanceof PyInstantiableType && ((PyInstantiableType)type).isDefinition()) {
|
||||
names.add("Type");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
def func():
|
||||
var = [1, 2, 3]
|
||||
v<caret>ar
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
from typing import List
|
||||
|
||||
|
||||
def func():
|
||||
var: [List[int]] = [1, 2, 3]
|
||||
var
|
||||
+4
@@ -203,6 +203,10 @@ public class PyAnnotateVariableTypeIntentionTest extends PyIntentionTestCase {
|
||||
doAnnotationTest();
|
||||
}
|
||||
|
||||
public void testAnnotationListType() {
|
||||
doAnnotationTest();
|
||||
}
|
||||
|
||||
private void doAnnotationTest() {
|
||||
doTest(LanguageLevel.PYTHON36);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user