-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working
Description
Environment data
- pyright 1.1.349
- python version 3.11.6
Code snippet
from typing import Generic
from typing import Literal
from typing import TypeAlias
from typing import TypeVar
A_float: TypeAlias = Literal["float32", "float64"]
A_numeric: TypeAlias = Literal["int32", "int64"] | A_float
Tdtype = TypeVar("Tdtype", bound=A_numeric)
class TypedArray(Generic[Tdtype]):
pass
Tdtype_float = TypeVar("Tdtype_float", bound=A_float)
# WORKS
OptionalFloatArray: TypeAlias = TypedArray[Tdtype_float] | None
# FAILS but equivalent
OptionalArray: TypeAlias = TypedArray[Tdtype] | None
OptionalFloatArray_: TypeAlias = OptionalArray[Tdtype_float]
# error: Could not specialize type "OptionalArray[Tdtype@OptionalArray]"
# "Literal['float32']" cannot be assigned to type "Literal['int32']"
# "Literal['float64']" cannot be assigned to type "Literal['int64']"Error description
Valid aliases with TypeVars raise error if Literal bounds are narrowed.
- Seems to only happen when using Literals in both bounds
- Does not happen if there is only one Literal in
A_float - Error description indicates that the bug is caused by doing subtype comparison in the wrong order
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working