diff --git a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java index ee7487323d4a..1589d7d26e82 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java +++ b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java @@ -131,9 +131,9 @@ public class PyTypeAssertionEvaluator extends PyRecursiveElementVisitor { } private void processIn(@NotNull PyExpression lhs, @NotNull PyExpression rhs) { - if (rhs instanceof PyTupleExpression tupleExpr) { + if (rhs instanceof PyTupleExpression || rhs instanceof PyListLiteralExpression || rhs instanceof PySetLiteralExpression) { pushAssertion(lhs, myPositive, (TypeEvalContext context) -> { - PyExpression[] elements = tupleExpr.getElements(); + PyExpression[] elements = ((PySequenceExpression)rhs).getElements(); List types = new ArrayList<>(elements.length); for (PyExpression element : elements) { PyType type = PyLiteralType.isNone(element) ? PyBuiltinCache.getInstance(element).getNoneType() : getLiteralType(element, context); diff --git a/python/testSrc/com/jetbrains/python/Py3TypeTest.java b/python/testSrc/com/jetbrains/python/Py3TypeTest.java index 925d32a869ed..333b69f1ad0c 100644 --- a/python/testSrc/com/jetbrains/python/Py3TypeTest.java +++ b/python/testSrc/com/jetbrains/python/Py3TypeTest.java @@ -737,6 +737,18 @@ public class Py3TypeTest extends PyTestCase { if a in (1, 2, ""): expr = a """); + doTest("Literal[1, 2]", + """ + def f(a: int): + if a in {1, 2, ""}: + expr = a + """); + doTest("Literal[1, 2]", + """ + def f(a: int): + if a in [1, 2, ""]: + expr = a + """); doTest("Literal[-10, \"a\"]", """ from enum import Enum