Skip to content

Commit 78d2e5c

Browse files
authored
PEP 827: Minor fixes and cleanups (#4976)
1 parent 6f37006 commit 78d2e5c

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

peps/pep-0827.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,7 @@ Boolean operators
613613
Technically this relation is "consistency" in the typing spec, not
614614
equivalence.
615615

616-
* ``Bool[T]``: Returns ``Literal[True]`` if ``T`` is also
617-
``Literal[True]`` or a union containing it.
616+
* ``Bool[T]``: Returns ``Literal[True]`` if ``T`` is also ``Literal[True]``.
618617
Equivalent to ``IsAssignable[T, Literal[True]] and not IsAssignable[T, Never]``.
619618

620619
This is useful for invoking "helper aliases" that return a boolean
@@ -640,7 +639,7 @@ Basic operators
640639
fail in a runtime evaluator of types.)
641640

642641
Special forms require special handling: the arguments list of a
643-
``Callable`` will be packed in a tuple and a ``...`` will be treated
642+
``Callable`` will be packed in a ``Params`` and a ``...`` will be treated
644643
as ``*args: Any`` and ``**kwargs: Any``, represented with the new
645644
``Param`` types.
646645

@@ -855,8 +854,11 @@ Many of the builtin operations are "lifted" over ``Union``.
855854

856855
For example::
857856

858-
Concat[Literal['a'] | Literal['b'], Literal['c'] | Literal['d']] = (
859-
Literal['ac'] | Literal['ad'] | Literal['bc'] | Literal['bd']
857+
Slice[tuple[A, B, C], Literal[0] | Literal[1], Literal[2] | Literal[3]] = (
858+
tuple[A, B]
859+
| tuple[A, B, C]
860+
| tuple[B]
861+
| tuple[B, C]
860862
)
861863

862864

@@ -1326,7 +1328,7 @@ unbound type variables and let them be generalized::
13261328
type Foo = NewProtocol[
13271329
Member[
13281330
Literal["process"],
1329-
Callable[[T], set[T] if IsAssignable[T, int] else T]
1331+
Callable[[T], T if IsAssignable[T, list] else list[T]]
13301332
]
13311333
]
13321334

@@ -1341,6 +1343,18 @@ functions with explicit generic annotations. For old-style generics,
13411343
we'll probably have to try to evaluate it and then raise an error when
13421344
we encounter a variable.)
13431345

1346+
With our real syntax, this look likes::
1347+
1348+
type Foo = NewProtocol[
1349+
Member[
1350+
Literal["process"],
1351+
GenericCallable[
1352+
tuple[T],
1353+
lambda T: Callable[[T], T if IsAssignable[T, list] else list[T]],
1354+
],
1355+
]
1356+
]
1357+
13441358
The reason we suggest restricting the use of ``GenericCallable`` to
13451359
the type argument of ``Member`` is because impredicative
13461360
polymorphism (where you can instantiate type variables with other

0 commit comments

Comments
 (0)