Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When inferring comparison operators, return a definite type instead of NO_VALUES for the in/not in operator #2014

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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