mirror of https://github.com/astral-sh/ruff
update variables.md
This commit is contained in:
parent
09f0756ac1
commit
a4585f774b
|
|
@ -107,15 +107,15 @@ reveal_type(S) # revealed: TypeVar
|
|||
### No explicit specialization
|
||||
|
||||
A type variable itself cannot be explicitly specialized; the result of the specialization is
|
||||
`Unknown`. However, anything designated as a generic type alias by `typing.TypeAlias` can be
|
||||
explicitly specialized.
|
||||
`Unknown`. However, generic PEP 613 type aliases that point to type variables can be explicitly
|
||||
specialized.
|
||||
|
||||
```py
|
||||
from typing import TypeVar, TypeAlias
|
||||
|
||||
T = TypeVar("T")
|
||||
BareAnnotated = T
|
||||
Annotated: TypeAlias = T
|
||||
ImplicitPositive = T
|
||||
Positive: TypeAlias = T
|
||||
|
||||
def _(
|
||||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||
|
|
@ -123,8 +123,8 @@ def _(
|
|||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||
b: T[T],
|
||||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||
c: BareAnnotated[int],
|
||||
d: Annotated[int],
|
||||
c: ImplicitPositive[int],
|
||||
d: Positive[int],
|
||||
):
|
||||
reveal_type(a) # revealed: Unknown
|
||||
reveal_type(b) # revealed: Unknown
|
||||
|
|
|
|||
|
|
@ -101,18 +101,17 @@ def f[T: (int,)]():
|
|||
### No explicit specialization
|
||||
|
||||
A type variable itself cannot be explicitly specialized; the result of the specialization is
|
||||
`Unknown`. However, anything designated as a generic type alias by a type statement can be
|
||||
explicitly specialized.
|
||||
`Unknown`. However, generic type aliases that point to type variables can be explicitly specialized.
|
||||
|
||||
```py
|
||||
type Annotated[T] = T
|
||||
type Positive[T] = T
|
||||
|
||||
def _[T](
|
||||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||
a: T[int],
|
||||
# error: [invalid-type-form] "A type variable itself cannot be specialized"
|
||||
b: T[T],
|
||||
c: Annotated[int],
|
||||
c: Positive[int],
|
||||
):
|
||||
reveal_type(a) # revealed: Unknown
|
||||
reveal_type(b) # revealed: Unknown
|
||||
|
|
|
|||
Loading…
Reference in New Issue