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 #2013

Closed
wants to merge 2 commits into from
Closed
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) <[email protected]>
- TingJia Wu (@WutingjiaX) <[email protected]>

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
5 changes: 5 additions & 0 deletions test/test_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,8 @@ def test_infer_after_parentheses(Script, code, column, expected):
assert completions == []
else:
assert [c.name for c in completions] == [expected]


def test_infer_in_operator(Script):
completions = Script("res = 'f' in 'foo'").infer(column=1)
assert completions[0].full_name == 'builtins.bool'
WutingjiaX marked this conversation as resolved.
Show resolved Hide resolved
Loading