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

support inferring some not expr #2016

Merged
merged 2 commits into from
Jul 12, 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
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