KEMBAR78
GitHub · Where software is built
Skip to content

Literal[negative int] #7844

@crusaderky

Description

@crusaderky

Python 3.7.4
typing_extensions 3.7.4
mypy git tip ( 0.750+dev.78f2df9d46198563106dd32cb4494678e97d71eb):

mypy returns false positives for negative integer literals.
errors inlined for convenience:

from typing_extensions import Literal


a: Literal[-2] = -2  # error: Incompatible types in assignment (expression has type "int", variable has type "Literal[-2]")
b: Literal[-1] = -1  # error: Incompatible types in assignment (expression has type "int", variable has type "Literal[-1]")
c: Literal[0] = 0
d: Literal[1] = 1
e: Literal[2] = 2

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions