diff --git a/python/src/com/jetbrains/python/psi/impl/PyBinaryExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyBinaryExpressionImpl.java index 30b0b885a57c..f4d0b036f0a3 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyBinaryExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyBinaryExpressionImpl.java @@ -166,11 +166,9 @@ public class PyBinaryExpressionImpl extends PyElementImpl implements PyBinaryExp } } final PyType type = markedCallee.getCallableType().getCallType(context, this); - if (!PyTypeChecker.isUnknown(type, context) && !(type instanceof PyNoneType)) { - types.add(type); - if (matched) { - matchedTypes.add(type); - } + types.add(type); + if (matched) { + matchedTypes.add(type); } } final boolean bothOperandsAreKnown = operandIsKnown(getLeftExpression(), context) && operandIsKnown(getRightExpression(), context); diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java index ba611eb66edd..d1c654a24d47 100644 --- a/python/testSrc/com/jetbrains/python/PyTypeTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java @@ -2263,6 +2263,19 @@ public class PyTypeTest extends PyTestCase { ); } + // PY-24960 + public void testOperatorReturnsAny() { + runWithLanguageLevel( + LanguageLevel.PYTHON35, + () -> doTest("Union[bool, Any]", + "from typing import Any\n" + + "class Bar:\n" + + " def __eq__(self, other) -> Any:\n" + + " pass\n" + + "expr = (Bar() == 2)") + ); + } + private static List getTypeEvalContexts(@NotNull PyExpression element) { return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(), TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());