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=foofromtypingimportLiteralfoo: boolifnotfoo:
print(1) # no error ✅bar: Literal[True]
ifnotbar:
print(1) # error: Statement is unreachable ✅
But this is not currently being applied to this situation:
# mypy: always-true=foofromtypingimportLiteralfoo: booldeff1() ->None:
iffoo:
returnprint(1) # error: Statement is unreachable ❌bar: Literal[True]
deff2() ->None:
ifbar:
returnprint(1) # error: Statement is unreachable ✅
Key:
✅ = correct behavior
❌ = sussy imposter behavior
Careful of #12325
Related: #11364
There is already some disparity between naturally literal bools(annotated with
Literalor narrowed) and artificially literal bools (platform,python-version,always-true,TYPE_CHECKINGetc):But this is not currently being applied to this situation:
Key:
✅ = correct behavior
❌ = sussy imposter behavior
Careful of #12325
Related: #11364