Skip to content

(🐞) Artificially literal bools not considered when performing reachability checks where branch terminates #12365

Description

@KotlinIsland

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions