Skip to content

Commit 2859e4f

Browse files
authored
Support inferring not expr to bool (#2016)
* support inferring some not expr * format --------- Co-authored-by: wutingjia <[email protected]>
1 parent 8ee4c26 commit 2859e4f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

jedi/inference/syntax_tree.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,10 @@ def infer_factor(value_set, operator):
493493
elif operator == 'not':
494494
b = value.py__bool__()
495495
if b is None: # Uncertainty.
496-
return
497-
yield compiled.create_simple_object(value.inference_state, not b)
496+
yield list(value.inference_state.builtins_module.py__getattribute__('bool')
497+
.execute_annotation()).pop()
498+
else:
499+
yield compiled.create_simple_object(value.inference_state, not b)
498500
else:
499501
yield value
500502

@@ -645,10 +647,7 @@ def _infer_comparison_part(inference_state, context, left, operator, right):
645647
_bool_to_value(inference_state, False)
646648
])
647649
elif str_operator in ('in', 'not in'):
648-
return ValueSet([
649-
_bool_to_value(inference_state, True),
650-
_bool_to_value(inference_state, False)
651-
])
650+
return inference_state.builtins_module.py__getattribute__('bool').execute_annotation()
652651

653652
def check(obj):
654653
"""Checks if a Jedi object is either a float or an int."""

test/completion/basic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,6 @@ def __enter__(self):
431431

432432
#? bool()
433433
res = 'f' in 'foo'; res
434+
435+
#? bool()
436+
res = not {}; res

0 commit comments

Comments
 (0)