Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions peps/pep-0827.rst
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,7 @@ Boolean operators
Technically this relation is "consistency" in the typing spec, not
equivalence.

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

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

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

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

For example::

Concat[Literal['a'] | Literal['b'], Literal['c'] | Literal['d']] = (
Literal['ac'] | Literal['ad'] | Literal['bc'] | Literal['bd']
Slice[tuple[A, B, C], Literal[0] | Literal[1], Literal[2] | Literal[3]] = (
tuple[A, B]
| tuple[A, B, C]
| tuple[B]
| tuple[B, C]
)


Expand Down Expand Up @@ -1326,7 +1328,7 @@ unbound type variables and let them be generalized::
type Foo = NewProtocol[
Member[
Literal["process"],
Callable[[T], set[T] if IsAssignable[T, int] else T]
Callable[[T], T if IsAssignable[T, list] else list[T]]
]
]

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

With our real syntax, this look likes::
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
With our real syntax, this look likes::
With our real syntax, this looks like::

(another one for the next PR)


type Foo = NewProtocol[
Member[
Literal["process"],
GenericCallable[
tuple[T],
lambda T: Callable[[T], T if IsAssignable[T, list] else list[T]],
],
]
]

The reason we suggest restricting the use of ``GenericCallable`` to
the type argument of ``Member`` is because impredicative
polymorphism (where you can instantiate type variables with other
Expand Down
Loading