diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 8a0b2656..7983bef3 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -603,7 +603,11 @@ def _infer_comparison_part(inference_state, context, left, operator, right): if str_operator in ('is', '!=', '==', 'is not'): operation = COMPARISON_OPERATORS[str_operator] bool_ = operation(left, right) - return ValueSet([_bool_to_value(inference_state, bool_)]) + # Only if == returns True or != returns False, we can continue. + # There's no guarantee that they are not equal. This can help + # in some cases, but does not cover everything. + if (str_operator in ('is', '==')) == bool_: + return ValueSet([_bool_to_value(inference_state, bool_)]) if isinstance(left, VersionInfo): version_info = _get_tuple_ints(right) diff --git a/test/completion/flow_analysis.py b/test/completion/flow_analysis.py index 3eb50d5e..ed1f0533 100644 --- a/test/completion/flow_analysis.py +++ b/test/completion/flow_analysis.py @@ -75,6 +75,14 @@ def try_except(x): #? float() str() try_except(1) +def test_function(): + a = int(input()) + if a % 2 == 0: + return True + return "False" + +#? bool() str() +test_function() # ----------------- # elif @@ -145,7 +153,7 @@ elif 1 == True: a if check != 1: a = '' -#? str() +#? int() str() a if check == check: a = list diff --git a/test/static_analysis/branches.py b/test/static_analysis/branches.py index 458d854b..14ea9a7b 100644 --- a/test/static_analysis/branches.py +++ b/test/static_analysis/branches.py @@ -43,6 +43,9 @@ else: def addition(a, b): if type(a) == type(b): + # Might still be a type error, we might want to change this in the + # future. + #! 9 type-error-operation return a + b else: #! 9 type-error-operation diff --git a/test/test_inference/test_compiled.py b/test/test_inference/test_compiled.py index cab6e27c..92111b2a 100644 --- a/test/test_inference/test_compiled.py +++ b/test/test_inference/test_compiled.py @@ -174,10 +174,11 @@ def test_qualified_names(same_process_inference_state, obj, expected_names): def test_operation(Script, inference_state, create_compiled_object): b = create_compiled_object(bool) - true, = _infer_comparison_part( + false, true = _infer_comparison_part( inference_state, b.parent_context, left=list(b.execute_with_values())[0], operator=u'is not', right=b, ) + assert false.py__name__() == 'bool' assert true.py__name__() == 'bool'