diff --git a/python/src/com/jetbrains/python/codeInsight/typing/PyTypingAnnotationInjector.java b/python/src/com/jetbrains/python/codeInsight/typing/PyTypingAnnotationInjector.java index 95542c7ea604..602edb7a74e9 100644 --- a/python/src/com/jetbrains/python/codeInsight/typing/PyTypingAnnotationInjector.java +++ b/python/src/com/jetbrains/python/codeInsight/typing/PyTypingAnnotationInjector.java @@ -14,6 +14,8 @@ import com.jetbrains.python.codeInsight.functionTypeComments.PyFunctionTypeAnnot import com.jetbrains.python.documentation.doctest.PyDocstringLanguageDialect; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.types.PyLiteralType; +import com.jetbrains.python.psi.types.PyType; +import com.jetbrains.python.psi.types.PyTypeUtil; import com.jetbrains.python.psi.types.TypeEvalContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -92,7 +94,8 @@ public class PyTypingAnnotationInjector extends PyInjectorBase { if (!(parent instanceof PySubscriptionExpression)) return false; final TypeEvalContext context = TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()); - return Ref.deref(PyTypingTypeProvider.getType((PySubscriptionExpression)parent, context)) instanceof PyLiteralType; + final PyType type = Ref.deref(PyTypingTypeProvider.getType((PySubscriptionExpression)parent, context)); + return PyTypeUtil.toStream(type).allMatch(PyLiteralType.class::isInstance); } private static boolean isFunctionTypeComment(@NotNull PsiElement comment) { diff --git a/python/testSrc/com/jetbrains/python/PyTypingTest.java b/python/testSrc/com/jetbrains/python/PyTypingTest.java index 9edb3de54846..1f9608495a03 100644 --- a/python/testSrc/com/jetbrains/python/PyTypingTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypingTest.java @@ -1485,6 +1485,9 @@ public class PyTypingTest extends PyTestCase { doTestNoInjectedText("from typing import Literal\n" + "a: Literal[\"foo\"]\n"); + doTestNoInjectedText("from typing import Literal\n" + + "a: Literal[42, \"foo\", True]\n"); + doTestNoInjectedText("from typing import Literal\n" + "MyType = Literal[42, \"foo\", True]\n" + "a: MyType\n");