Skip to content
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

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

Closed
KotlinIsland opened this issue Nov 13, 2020 · 3 comments
Closed

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

KotlinIsland opened this issue Nov 13, 2020 · 3 comments

Comments

@KotlinIsland
Copy link
Contributor

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
                       ^
@KotlinIsland KotlinIsland added the bug mypy got something wrong label Nov 13, 2020
@prayatharth
Copy link

What problem exactly we are facing here ?

@JelleZijlstra
Copy link
Member

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

@hauntsaninja
Copy link
Collaborator

Duplicate of #12535

@hauntsaninja hauntsaninja marked this as a duplicate of #12535 Nov 12, 2023
@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants