-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongsemantic-analyzerProblems that happen during semantic analysisProblems that happen during semantic analysistopic-literal-typestopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly
Description
Bug Report, To Reproduce, & Actual Behaviour
See mypy playground
from typing import Literal
a: Literal[1 | None]
reveal_type(a)note: Revealed type is "Union[Literal[1], None]"
Success: no issues found in 1 source fileFor the runtime counterpart, this will result in a TypeError: unsupported operand type(s) for |: 'int' and 'NoneType' if the module doesn't have from __future__ import annotations or invalid results for runtime annotation inspectors (e.g. in the case of typing.Literal[1 | 2]).
Expected Behavior
Maybe:
error: Invalid type: Literal[...] cannot contain arbitrary expressions [valid-type]
note: Revealed type is "Any"Your Environment
- Mypy version used: 1.10
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.10 & 3.12
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongsemantic-analyzerProblems that happen during semantic analysisProblems that happen during semantic analysistopic-literal-typestopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly