Skip to content

Commit

Permalink
Support inferring not expr to bool (#2016)
Browse files Browse the repository at this point in the history
* support inferring some not expr

* format

---------

Co-authored-by: wutingjia <wutingjia@bytedance.com>
  • Loading branch information
WutingjiaX and wutingjia authored Jul 12, 2024
1 parent 8ee4c26 commit 2859e4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 5 additions & 6 deletions jedi/inference/syntax_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,10 @@ def infer_factor(value_set, operator):
elif operator == 'not':
b = value.py__bool__()
if b is None: # Uncertainty.
return
yield compiled.create_simple_object(value.inference_state, not b)
yield list(value.inference_state.builtins_module.py__getattribute__('bool')
.execute_annotation()).pop()
else:
yield compiled.create_simple_object(value.inference_state, not b)
else:
yield value

Expand Down Expand Up @@ -645,10 +647,7 @@ def _infer_comparison_part(inference_state, context, left, operator, right):
_bool_to_value(inference_state, False)
])
elif str_operator in ('in', 'not in'):
return ValueSet([
_bool_to_value(inference_state, True),
_bool_to_value(inference_state, False)
])
return inference_state.builtins_module.py__getattribute__('bool').execute_annotation()

def check(obj):
"""Checks if a Jedi object is either a float or an int."""
Expand Down
3 changes: 3 additions & 0 deletions test/completion/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,6 @@ def __enter__(self):

#? bool()
res = 'f' in 'foo'; res

#? bool()
res = not {}; res

0 comments on commit 2859e4f

Please sign in to comment.