Skip to content

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

Open
@KotlinIsland

Description

@KotlinIsland

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions