Skip to content

(🐞) always-true/always-false doesn't activate until it's truth is checked #12325

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 10, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Mar 10, 2022

test.py:

from typing import Literal


def foo(a: Literal[True]) -> None:
    ...


FOO: bool
foo(FOO)  # error: Argument 1 to "foo" has incompatible type "bool"; expected "Literal[True]"  [arg-type]
reveal_type(FOO)  # note: Revealed type is "builtins.bool"
if not FOO:
    pass
reveal_type(FOO)  # note: Revealed type is "Literal[True]"
if not FOO:
    pass
import test2

test2.py:

from test import FOO

reveal_type(FOO)  # note: Revealed type is "builtins.bool"
if FOO:
    pass
reveal_type(FOO)  # note: Revealed type is "Literal[True]"

> mypy --always-true FOO test.py

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Mar 10, 2022
@KotlinIsland KotlinIsland changed the title (🐞) always-true doesn't activate until (🐞) always-true/always-false doesn't activate until it's truth is checked Mar 10, 2022
@Zeckie
Copy link

Zeckie commented Mar 13, 2022

Can you explain what you think is wrong, and why?

eg. is it that due to --always-true FOO on command line, the variable FOO should always be treated as Literal[True]?

Is this going to have flow on effects, such as having the code inside if not FOO: being unreachable?

@KotlinIsland
Copy link
Contributor Author

@Zeckie You can read about the expected functionality here

There are some negative consequences to this functionality, such as #11364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants