Skip to content

Literal[inf] / Literal[nan]: misleading error message #11208

@crusaderky

Description

@crusaderky
from math import inf, nan
from typing import Literal

x: Literal[1.1]
y: Literal[inf]
z: Literal[nan]

mypy 0.910 output:

a.py:4: error: Parameter 1 of Literal[...] cannot be of type "float"
a.py:5: error: Parameter 1 of Literal[...] is invalid
a.py:5: error: Variable "math.inf" is not valid as a type
a.py:5: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
a.py:6: error: Parameter 1 of Literal[...] is invalid
a.py:6: error: Variable "math.nan" is not valid as a type
a.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases

The linked documentation is unrelated to the issue, as Literal does not expect types.
Expected output:

a.py:4: error: Parameter 1 of Literal[...] cannot be of type "float"
a.py:5: error: Parameter 1 of Literal[...] cannot be of type "float"
a.py:6: error: Parameter 1 of Literal[...] cannot be of type "float"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions