Skip to content

Commit

Permalink
Merge pull request #2014 from WutingjiaX/feat/in_operator
Browse files Browse the repository at this point in the history
 When inferring comparison operators, return a definite type instead of NO_VALUES for the in/not in operator
  • Loading branch information
davidhalter authored Jul 10, 2024
2 parents 82d1902 + 4d09ac0 commit 8ee4c26
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Code Contributors
- Joseph Birkner (@josephbirkner)
- Márcio Mazza (@marciomazza)
- Martin Vielsmaier (@moser) <martin@vielsmaier.net>
- TingJia Wu (@WutingjiaX) <wutingjia@bytedance.com>

And a few more "anonymous" contributors.

Expand Down
5 changes: 4 additions & 1 deletion jedi/inference/syntax_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,10 @@ def _infer_comparison_part(inference_state, context, left, operator, right):
_bool_to_value(inference_state, False)
])
elif str_operator in ('in', 'not in'):
return NO_VALUES
return ValueSet([
_bool_to_value(inference_state, True),
_bool_to_value(inference_state, False)
])

def check(obj):
"""Checks if a Jedi object is either a float or an int."""
Expand Down
7 changes: 7 additions & 0 deletions test/completion/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,10 @@ def __enter__(self):
some_array = ['', '']
#! ['def upper']
some_array[some_not_defined_index].upper

# -----------------
# operator
# -----------------

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

0 comments on commit 8ee4c26

Please sign in to comment.