mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Support inferring not expr to bool (#2016)
* support inferring some not expr * format --------- Co-authored-by: wutingjia <wutingjia@bytedance.com>
This commit is contained in:
@@ -493,8 +493,10 @@ def infer_factor(value_set, operator):
|
|||||||
elif operator == 'not':
|
elif operator == 'not':
|
||||||
b = value.py__bool__()
|
b = value.py__bool__()
|
||||||
if b is None: # Uncertainty.
|
if b is None: # Uncertainty.
|
||||||
return
|
yield list(value.inference_state.builtins_module.py__getattribute__('bool')
|
||||||
yield compiled.create_simple_object(value.inference_state, not b)
|
.execute_annotation()).pop()
|
||||||
|
else:
|
||||||
|
yield compiled.create_simple_object(value.inference_state, not b)
|
||||||
else:
|
else:
|
||||||
yield value
|
yield value
|
||||||
|
|
||||||
@@ -645,10 +647,7 @@ def _infer_comparison_part(inference_state, context, left, operator, right):
|
|||||||
_bool_to_value(inference_state, False)
|
_bool_to_value(inference_state, False)
|
||||||
])
|
])
|
||||||
elif str_operator in ('in', 'not in'):
|
elif str_operator in ('in', 'not in'):
|
||||||
return ValueSet([
|
return inference_state.builtins_module.py__getattribute__('bool').execute_annotation()
|
||||||
_bool_to_value(inference_state, True),
|
|
||||||
_bool_to_value(inference_state, False)
|
|
||||||
])
|
|
||||||
|
|
||||||
def check(obj):
|
def check(obj):
|
||||||
"""Checks if a Jedi object is either a float or an int."""
|
"""Checks if a Jedi object is either a float or an int."""
|
||||||
|
|||||||
@@ -431,3 +431,6 @@ some_array[some_not_defined_index].upper
|
|||||||
|
|
||||||
#? bool()
|
#? bool()
|
||||||
res = 'f' in 'foo'; res
|
res = 'f' in 'foo'; res
|
||||||
|
|
||||||
|
#? bool()
|
||||||
|
res = not {}; res
|
||||||
|
|||||||
Reference in New Issue
Block a user