There is already some disparity between naturally literal bools(annotated with Literal or narrowed) and artificially literal bools (platform, python-version, always-true, TYPE_CHECKING etc):
# mypy: always-true=foo
from typing import Literal
foo: bool
if not foo:
print(1) # no error ✅
bar: Literal[True]
if not bar:
print(1) # error: Statement is unreachable ✅
But this is not currently being applied to this situation:
# mypy: always-true=foo
from typing import Literal
foo: bool
def f1() -> None:
if foo:
return
print(1) # error: Statement is unreachable ❌
bar: Literal[True]
def f2() -> None:
if bar:
return
print(1) # error: Statement is unreachable ✅
Key:
✅ = correct behavior
❌ = sussy imposter behavior
Careful of #12325
Related: #11364