items: tuple[Literal[42], Literal['foo']] = (42, 'foo')
\ No newline at end of file
diff --git a/python/testSrc/com/jetbrains/python/Py3TypeTest.java b/python/testSrc/com/jetbrains/python/Py3TypeTest.java
index a5d10806c2c6..88593b8cddca 100644
--- a/python/testSrc/com/jetbrains/python/Py3TypeTest.java
+++ b/python/testSrc/com/jetbrains/python/Py3TypeTest.java
@@ -3646,7 +3646,7 @@ public class Py3TypeTest extends PyTestCase {
// PY-64474
public void testTupleElementAccessedWithNegativeIndex() {
- doTest("bool",
+ doTest("Literal[True]",
"""
xs = (1, True, "foo")
expr = xs[-2]
@@ -5151,6 +5151,13 @@ public class Py3TypeTest extends PyTestCase {
""");
}
+ @TestFor(issues = "PY-57621")
+ public void testTupleWithLiteralValues() {
+ doTest("tuple[Literal[1]]", """
+ expr = (1,)
+ """);
+ }
+
// PY-87575
public void testIterDefinedInMetaclass() {
doTest("set[int]", """
diff --git a/python/testSrc/com/jetbrains/python/PyTypeConversionTest.java b/python/testSrc/com/jetbrains/python/PyTypeConversionTest.java
index ff7b76ff7dd7..ef92b857bcfc 100644
--- a/python/testSrc/com/jetbrains/python/PyTypeConversionTest.java
+++ b/python/testSrc/com/jetbrains/python/PyTypeConversionTest.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python;
import com.jetbrains.python.documentation.PythonDocumentationProvider;
@@ -32,7 +32,7 @@ public final class PyTypeConversionTest extends PyTestCase {
}
public void testTupleToTypingIterable() {
- doTest("typing.Iterable", "Iterable[int | str]", """
+ doTest("typing.Iterable", "Iterable[Literal[1, \"foo\"]]", """
expr = (1, "foo")
""");
}
diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java
index 7d0040682c53..b48c1feaad3c 100644
--- a/python/testSrc/com/jetbrains/python/PyTypeTest.java
+++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python;
import com.google.common.collect.ImmutableList;
@@ -52,7 +52,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testTupleType() {
- doTest("str",
+ doTest("Literal['a']",
"t = ('a', 2)\n" +
"expr = t[0]");
doTest("List[bool]",
@@ -68,7 +68,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testTupleAssignmentType() {
- doTest("str",
+ doTest("Literal['a']",
"t = ('a', 2)\n" +
"(expr, q) = t");
}
@@ -106,7 +106,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testUnionOfTuples() {
- doTest("Union[Tuple[int, str], Tuple[str, int]]",
+ doTest("Union[Tuple[Literal[1], Literal['a']], Tuple[Literal['a'], Literal[1]]]",
"""
def x(b):
if b:
@@ -298,7 +298,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testIsInstance2() {
- doTest("str",
+ doTest("Literal[\"\"]",
"""
x = ""
if isinstance(x, (1, "")):
@@ -1002,7 +1002,7 @@ public class PyTypeTest extends PyTestCase {
// PY-9334
public void testIterateOverListOfNestedTuples() {
- doTest("str",
+ doTest("Literal['foo']",
"""
def f():
for i, (expr, v) in [(0, ('foo', []))]:
@@ -1047,7 +1047,7 @@ public class PyTypeTest extends PyTestCase {
// PY-10967
public void testDefaultTupleParameterMember() {
- doTest("int",
+ doTest("Literal[1]",
"""
def foo(xs=(1, 2)):
expr, foo = xs
@@ -1071,7 +1071,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testTupleFromTuple() {
- doTest("Tuple[str, int, int]",
+ doTest("Tuple[Literal['1'], Literal[2], Literal[3]]",
"expr = tuple(('1', 2, 3))");
}
@@ -1128,7 +1128,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testTupleIterationType() {
- doTest("Union[int, str]",
+ doTest("Literal[1, 'a']",
"""
xs = (1, 'a')
for expr in xs:
@@ -1138,35 +1138,35 @@ public class PyTypeTest extends PyTestCase {
// PY-12801
public void testTupleConcatenation() {
- doTest("Tuple[int, bool, str]",
+ doTest("Tuple[Literal[1], Literal[True], Literal['spam']]",
"expr = (1,) + (True, 'spam') + ()");
}
public void testTupleMultiplication() {
- doTest("Tuple[int, bool, int, bool]",
+ doTest("Tuple[Literal[1], Literal[False], Literal[1], Literal[False]]",
"expr = (1, False) * 2");
}
public void testTupleDestructuring() {
- doTest("str",
+ doTest("Literal['val']",
"_, expr = (1, 'val') ");
}
public void testParensTupleDestructuring() {
- doTest("str",
+ doTest("Literal['val']",
"(_, expr) = (1, 'val') ");
}
// PY-19825
public void testSubTupleDestructuring() {
- doTest("str",
+ doTest("Literal['val']",
"(a, (_, expr)) = (1, (2,'val')) ");
}
// PY-19825
public void testSubTupleIndirectDestructuring() {
- doTest("str",
+ doTest("Literal['val']",
"xs = (2,'val')\n" +
"(a, (_, expr)) = (1, xs) ");
}
@@ -1174,7 +1174,7 @@ public class PyTypeTest extends PyTestCase {
// PY-38928
public void testIterateListOfTuples() {
doTest(
- "str",
+ "Literal['foo']",
"""
for ((_, expr)) in [(1, 'foo')]:
pass
@@ -1670,9 +1670,11 @@ public class PyTypeTest extends PyTestCase {
}
public void testHeterogeneousTupleLiteral() {
- doTest("Tuple[str, int, int]", "expr = ('1', 1, 1)");
+ doTest("Tuple[Literal['1'], Literal[1], Literal[1]]", "expr = ('1', 1, 1)");
- doTest("Tuple[str, int, int, int, int, int, int, int, int, int, int]", "expr = ('1', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)");
+ doTest(
+ "Tuple[Literal['1'], Literal[1], Literal[1], Literal[1], Literal[1], Literal[1], Literal[1], Literal[1], Literal[1], Literal[1], Literal[1]]",
+ "expr = ('1', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)");
}
// PY-20818
@@ -2712,14 +2714,14 @@ public class PyTypeTest extends PyTestCase {
}
public void testUnpackingToNestedTargetsInSquareBracketsInAssignments() {
- doTest("int",
+ doTest("Literal[42]",
"""
[_, [[expr], _]] = "foo", ((42,), "bar")
""");
}
public void testUnpackingToNestedTargetsInSquareBracketsInForLoops() {
- doTest("str",
+ doTest("Literal[\"foo\"]",
"""
xs = [(1, ("foo",))]
for [_, [expr]] in xs:
@@ -2728,7 +2730,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testUnpackingToNestedTargetsInSquareBracketsInComprehensions() {
- doTest("str",
+ doTest("Literal[\"foo\"]",
"""
xs = [(1, ("foo",))]
ys = [expr for [_, [expr]] in xs]
diff --git a/python/testSrc/com/jetbrains/python/PyTypingTest.java b/python/testSrc/com/jetbrains/python/PyTypingTest.java
index 2ad166bc4ff6..7ffe8db52838 100644
--- a/python/testSrc/com/jetbrains/python/PyTypingTest.java
+++ b/python/testSrc/com/jetbrains/python/PyTypingTest.java
@@ -6158,6 +6158,19 @@ public class PyTypingTest extends PyTestCase {
""");
}
+ @TestFor(issues="PY-57621")
+ public void testEnumTuple() {
+ doTest("tuple[int, str]", """
+ from enum import Enum
+
+ class Color(Enum):
+ RED = 1, "red"
+ BLUE = 2, "blue"
+
+ expr = Color.BLUE.value
+ """);
+ }
+
// PY-76149
public void testDataclassTransformConstructorSignatureWithFieldsAnnotatedWithDescriptor() {
doTestExpressionUnderCaret("(id: int, name: str) -> MyClass", """
diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java
index 31cc1f54c8d8..a61b59e33f79 100644
--- a/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java
+++ b/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.inspections;
import com.intellij.openapi.util.RecursionManager;
@@ -1874,8 +1874,8 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase {
foo(1, bar, args=(0, 'foo'))
foo(1, baz, args=(0, 'foo', 1.0, False))
- foo(1, bar,