Skip to content

Commit 8853f22

Browse files
authored
Unreachable expressions: treat non-zero ints as truthy (#10562)
1 parent 98ac487 commit 8853f22

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5096,7 +5096,7 @@ def gen_unique_name(base: str, table: SymbolTable) -> str:
50965096
def is_true_literal(n: Expression) -> bool:
50975097
"""Returns true if this expression is the 'True' literal/keyword."""
50985098
return (refers_to_fullname(n, 'builtins.True')
5099-
or isinstance(n, IntExpr) and n.value == 1)
5099+
or isinstance(n, IntExpr) and n.value != 0)
51005100

51015101

51025102
def is_false_literal(n: Expression) -> bool:

test-data/unit/check-unreachable-code.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ def foo() -> bool: ...
908908
lst = [1, 2, 3, 4]
909909

910910
a = True or foo() # E: Right operand of "or" is never evaluated
911+
b = 42 or False # E: Right operand of "or" is never evaluated
911912
d = False and foo() # E: Right operand of "and" is never evaluated
912913
e = True or (True or (True or foo())) # E: Right operand of "or" is never evaluated
913914
f = (True or foo()) or (True or foo()) # E: Right operand of "or" is never evaluated

0 commit comments

Comments
 (0)