forked from VimPlug/jedi
If branch inference should not trigger for things we don't know, fixes #1530
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user