From c8ec189ea932a52158e27b02f763b392d11bc3bb Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Wed, 2 Aug 2017 15:54:57 +0300 Subject: [PATCH] PY-24960 Fixed: False-positive warning about results of comparison operators for imported types Don't ignore unknown and none types as operator call types. --- .../python/psi/impl/PyBinaryExpressionImpl.java | 8 +++----- python/testSrc/com/jetbrains/python/PyTypeTest.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) 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());