From 28e74fcc045b31bf0cb9c12dbea0e9fcc166cb60 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Sat, 27 Jan 2018 22:57:53 +0300 Subject: [PATCH] PY-16412 Import Tuple for parametrized types of tuples --- .../codeInsight/intentions/PyTypeHintGenerationUtil.java | 3 +++ .../annotationTupleType.py | 1 + .../annotationTupleType_after.py | 3 +++ .../intentions/PyAnnotateVariableTypeIntentionTest.java | 4 ++++ 4 files changed, 11 insertions(+) create mode 100644 python/testData/intentions/PyAnnotateVariableTypeIntentionTest/annotationTupleType.py create mode 100644 python/testData/intentions/PyAnnotateVariableTypeIntentionTest/annotationTupleType_after.py diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyTypeHintGenerationUtil.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyTypeHintGenerationUtil.java index 9ec23b4b8fe1..b36fbcba8be1 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyTypeHintGenerationUtil.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyTypeHintGenerationUtil.java @@ -305,6 +305,9 @@ public class PyTypeHintGenerationUtil { classes.add(pyClass); } } + else if (type instanceof PyTupleType) { + names.add("Tuple"); + } for (PyType pyType : ((PyCollectionType)type).getElementTypes()) { collectImportTargetsFromType(pyType, classes, names); } diff --git a/python/testData/intentions/PyAnnotateVariableTypeIntentionTest/annotationTupleType.py b/python/testData/intentions/PyAnnotateVariableTypeIntentionTest/annotationTupleType.py new file mode 100644 index 000000000000..c7651286d18c --- /dev/null +++ b/python/testData/intentions/PyAnnotateVariableTypeIntentionTest/annotationTupleType.py @@ -0,0 +1 @@ +var = (1, 'foo', None) \ No newline at end of file diff --git a/python/testData/intentions/PyAnnotateVariableTypeIntentionTest/annotationTupleType_after.py b/python/testData/intentions/PyAnnotateVariableTypeIntentionTest/annotationTupleType_after.py new file mode 100644 index 000000000000..fe382ba86b97 --- /dev/null +++ b/python/testData/intentions/PyAnnotateVariableTypeIntentionTest/annotationTupleType_after.py @@ -0,0 +1,3 @@ +from typing import Tuple + +var: [Tuple[int, str, None]] = (1, 'foo', None) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/intentions/PyAnnotateVariableTypeIntentionTest.java b/python/testSrc/com/jetbrains/python/intentions/PyAnnotateVariableTypeIntentionTest.java index f5c649d8ab02..16e885f24ad5 100644 --- a/python/testSrc/com/jetbrains/python/intentions/PyAnnotateVariableTypeIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/intentions/PyAnnotateVariableTypeIntentionTest.java @@ -207,6 +207,10 @@ public class PyAnnotateVariableTypeIntentionTest extends PyIntentionTestCase { doAnnotationTest(); } + public void testAnnotationTupleType() { + doAnnotationTest(); + } + private void doAnnotationTest() { doTest(LanguageLevel.PYTHON36); }