Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
KotlinIsland opened this issue Mar 16, 2022 · 1 comment · May be fixed by #18539
Labels
feature topic-reachability Detecting unreachable code

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Mar 16, 2022

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

@KotlinIsland KotlinIsland changed the title (🎁) Consider artificially literal bools when performing reachability checks (🐞) Artificially literal bools not consider when performing reachability checks where branch terminates Mar 17, 2022
@KotlinIsland KotlinIsland changed the title (🐞) Artificially literal bools not consider when performing reachability checks where branch terminates (🐞) Artificially literal bools not considered when performing reachability checks where branch terminates Mar 17, 2022
@KotlinIsland
Copy link
Contributor Author

@a_maintainer Can you mark this as bug(🐞), I updated the title, but can't change the tags(😥)

@JelleZijlstra JelleZijlstra added the topic-reachability Detecting unreachable code label Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-reachability Detecting unreachable code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants