mirror of https://github.com/astral-sh/ruff
add TODO comment about PEP 613 type aliases
This commit is contained in:
parent
b6da8547d9
commit
cdec0f9421
|
|
@ -107,21 +107,32 @@ reveal_type(S) # revealed: TypeVar
|
||||||
### No explicit specialization
|
### No explicit specialization
|
||||||
|
|
||||||
A type variable itself cannot be explicitly specialized; the result of the specialization is
|
A type variable itself cannot be explicitly specialized; the result of the specialization is
|
||||||
`Unknown`.
|
`Unknown`. However, anything designated as a generic type alias by `typing.TypeAlias` can be
|
||||||
|
explicitly specialized.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
from typing import TypeVar
|
from typing import TypeVar, TypeAlias
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
BareAnnotated = T
|
||||||
|
Annotated: TypeAlias = T
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||||
x: T[int],
|
a: T[int],
|
||||||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||||
y: T[T],
|
b: T[T],
|
||||||
|
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||||
|
c: BareAnnotated[int],
|
||||||
|
# TODO: no error
|
||||||
|
# error: [invalid-type-form]
|
||||||
|
d: Annotated[int],
|
||||||
):
|
):
|
||||||
reveal_type(x) # revealed: Unknown
|
reveal_type(a) # revealed: Unknown
|
||||||
reveal_type(y) # revealed: Unknown
|
reveal_type(b) # revealed: Unknown
|
||||||
|
reveal_type(c) # revealed: Unknown
|
||||||
|
# TODO: should be `int`
|
||||||
|
reveal_type(d) # revealed: Unknown
|
||||||
```
|
```
|
||||||
|
|
||||||
### Type variables with a default
|
### Type variables with a default
|
||||||
|
|
|
||||||
|
|
@ -101,17 +101,22 @@ def f[T: (int,)]():
|
||||||
### No explicit specialization
|
### No explicit specialization
|
||||||
|
|
||||||
A type variable itself cannot be explicitly specialized; the result of the specialization is
|
A type variable itself cannot be explicitly specialized; the result of the specialization is
|
||||||
`Unknown`.
|
`Unknown`. However, anything designated as a generic type alias by a type statement can be
|
||||||
|
explicitly specialized.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
type Annotated[T] = T
|
||||||
|
|
||||||
def _[T](
|
def _[T](
|
||||||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||||
x: T[int],
|
a: T[int],
|
||||||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||||
y: T[T],
|
b: T[T],
|
||||||
|
c: Annotated[int],
|
||||||
):
|
):
|
||||||
reveal_type(x) # revealed: Unknown
|
reveal_type(a) # revealed: Unknown
|
||||||
reveal_type(y) # revealed: Unknown
|
reveal_type(b) # revealed: Unknown
|
||||||
|
reveal_type(c) # revealed: int
|
||||||
```
|
```
|
||||||
|
|
||||||
## Invalid uses
|
## Invalid uses
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue