Closed Yazan-Sharaya closed 2 days ago
Mypy is correct here. The and
operator evaluates to its right-hand side if the left-hand side is truthy. You can try it in the REPL:
>>> my_list = [1]
... should_update: bool = True and my_list
...
>>> should_update
[1]
You are right, I don't know how I didn't catch that. Thanks for the quick response!
Bug Report
Mypy fails to recognize that truth value testing results in boolean for sequences.
To Reproduce
Actual Behavior
Mypy thinks the type of the new variable is whatever the type of the sequence is, list[int] in this case. error: Incompatible types in assignment (expression has type "list[int]", variable has type "bool") [assignment]
Your Environment
mypy.ini
(and other config files): None