forked from VimPlug/jedi
If branch inference should not trigger for things we don't know, fixes #1530
This commit is contained in:
@@ -603,6 +603,10 @@ def _infer_comparison_part(inference_state, context, left, operator, right):
|
|||||||
if str_operator in ('is', '!=', '==', 'is not'):
|
if str_operator in ('is', '!=', '==', 'is not'):
|
||||||
operation = COMPARISON_OPERATORS[str_operator]
|
operation = COMPARISON_OPERATORS[str_operator]
|
||||||
bool_ = operation(left, right)
|
bool_ = operation(left, right)
|
||||||
|
# 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_)])
|
return ValueSet([_bool_to_value(inference_state, bool_)])
|
||||||
|
|
||||||
if isinstance(left, VersionInfo):
|
if isinstance(left, VersionInfo):
|
||||||
|
|||||||
@@ -75,6 +75,14 @@ def try_except(x):
|
|||||||
#? float() str()
|
#? float() str()
|
||||||
try_except(1)
|
try_except(1)
|
||||||
|
|
||||||
|
def test_function():
|
||||||
|
a = int(input())
|
||||||
|
if a % 2 == 0:
|
||||||
|
return True
|
||||||
|
return "False"
|
||||||
|
|
||||||
|
#? bool() str()
|
||||||
|
test_function()
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# elif
|
# elif
|
||||||
@@ -145,7 +153,7 @@ elif 1 == True:
|
|||||||
a
|
a
|
||||||
if check != 1:
|
if check != 1:
|
||||||
a = ''
|
a = ''
|
||||||
#? str()
|
#? int() str()
|
||||||
a
|
a
|
||||||
if check == check:
|
if check == check:
|
||||||
a = list
|
a = list
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ else:
|
|||||||
|
|
||||||
def addition(a, b):
|
def addition(a, b):
|
||||||
if type(a) == type(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
|
return a + b
|
||||||
else:
|
else:
|
||||||
#! 9 type-error-operation
|
#! 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):
|
def test_operation(Script, inference_state, create_compiled_object):
|
||||||
b = create_compiled_object(bool)
|
b = create_compiled_object(bool)
|
||||||
true, = _infer_comparison_part(
|
false, true = _infer_comparison_part(
|
||||||
inference_state, b.parent_context,
|
inference_state, b.parent_context,
|
||||||
left=list(b.execute_with_values())[0],
|
left=list(b.execute_with_values())[0],
|
||||||
operator=u'is not',
|
operator=u'is not',
|
||||||
right=b,
|
right=b,
|
||||||
)
|
)
|
||||||
|
assert false.py__name__() == 'bool'
|
||||||
assert true.py__name__() == 'bool'
|
assert true.py__name__() == 'bool'
|
||||||
|
|||||||
Reference in New Issue
Block a user