Closed as not planned
Description
Bug Report
I am trying to create a type alias for typings.Annotated
to improve code readability, but mypy fails during static type checking. In more details, I have the following code:
from typing import Annotated
import torch
import numpy
# This works
a: Annotated[torch.Tensor | numpy.ndarray, 4] | None = None
# This fails, I expect it to work
type T[*args] = Annotated[torch.Tensor | numpy.ndarray, *args]
b : T[4] | None = None
Mypy fails during static checking, but only for the second type annotation. I expect instead that both type annotations would behave the same way. This is the error: error: Invalid type: try using Literal[4] instead? [valid-type]
.
To Reproduce
See above.
Expected Behavior
See above.
Actual Behavior
See above.
Your Environment
- Mypy version used: mypy 1.15.0 (compiled: yes)
- Mypy command-line flags: None, just the file name
- Mypy configuration options from
mypy.ini
(and other config files): No other configs - Python version used: 3.12.9