Skip to content

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

Open

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

Activity

  1. changed the title [-](馃悶) `always-true` doesn't activate until [/-] [+](馃悶) `always-true`/`always-false` doesn't activate until it's truth is checked[/+] on Mar 10, 2022
  2. Zeckie commented on Mar 13, 2022

    @Zeckie

    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?

  3. KotlinIsland commented on Mar 13, 2022

    @KotlinIsland
    ContributorAuthor

    @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

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