Skip to content

Constrain/narrow literal type with 'in' checks #9718

Closed as not planned
Closed as not planned

Description

@KotlinIsland
from typing import Literal

a: Literal[1, 2, 3] = 2
assert a in (1, 2)
b: Literal[1, 2] = a
error: Incompatible types in assignment (expression has type "Union[Literal[1], Literal[2], Literal[3]]", variable has 
type "Union[Literal[1], Literal[2]]")
    b: Literal[1, 2] = a
                       ^

Activity

  1. prayatharth commented on Nov 13, 2020

    @prayatharth

    What problem exactly we are facing here ?

  2. JelleZijlstra commented on Nov 13, 2020

    @JelleZijlstra
    Member

    The report seems clear enough to me. It's a reasonable request; a PR would be welcome.

  3. added and removed
    bugmypy got something wrong
    on Nov 13, 2020
  4. hauntsaninja commented on Nov 12, 2023

    @hauntsaninja
    Collaborator

    Duplicate of #12535

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions