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

expression has type "Literal[-1]", variable has type "Literal[-1]" #16727

Closed
JelleZijlstra opened this issue Jan 2, 2024 · 0 comments · Fixed by #16729
Closed

expression has type "Literal[-1]", variable has type "Literal[-1]" #16727

JelleZijlstra opened this issue Jan 2, 2024 · 0 comments · Fixed by #16729
Labels
bug mypy got something wrong topic-literal-types

Comments

@JelleZijlstra
Copy link
Member

from typing import Literal

x: Literal[-True] = -1

results in

main.py:3: error: Incompatible types in assignment (expression has type "Literal[-1]", variable has type "Literal[-1]")  [assignment]

https://mypy-play.net/?mypy=latest&python=3.10&gist=3e6413c5ba1b82c11ff2ae6b66abd03e

Instead mypy should reject the type declaration.

@JelleZijlstra JelleZijlstra added bug mypy got something wrong topic-literal-types labels Jan 2, 2024
JelleZijlstra added a commit to JelleZijlstra/mypy that referenced this issue Jan 2, 2024
Implements python/typing#1550

Fixes python#16727 (a trivial bug I found while implementing this feature)
hauntsaninja pushed a commit that referenced this issue Jan 2, 2024
Implements python/typing#1550

Fixes #16727 (a trivial bug I found while implementing this feature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-literal-types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant