The handlers of the group G so far, needing R; H is the
tags of the RPCs still without one, for a group that lists its tags
(Never once all have one, and for a group that does not). Immutable:
handle gives a new one.
Attributes#
| Attribute | Type | Description |
|---|---|---|
group | = group | |
by_tag | Mapping[str, HandlerFn] |
Functions#
__init__#
__init__(group, by_tag) -> None| Parameter | Type | Description |
|---|---|---|
group | type[RpcGroup[Any]] | |
by_tag | Mapping[str, HandlerFn] |
def __init__(self, group: type[RpcGroup[Any]], by_tag: Mapping[str, HandlerFn]) -> None:
self.group = group
self._by_tag = dict(by_tag)handle#
handle[P, S, E1, T: str](rpc: Rpc[P, S, E1, Never, Never, T], /) -> Bound[G_co, RpcRequest[P], S, E1, Never, R_co, T, H]
handle[P, S, E1, MP, ME, MT, T: str](rpc: Rpc[P, S, E1, RpcMiddleware[MP, ME, Any], MT, T], /) -> Bound[G_co, RpcRequest[P], S, E1 | ME, MP, R_co | MT, T, H]
handle[P, A, E1, T: str](rpc: StreamRpc[P, A, E1, Never, Never, T], /) -> StreamBound[G_co, RpcRequest[P], A, E1, Never, R_co, T, H]
handle[P, A, E1, MP, ME, MT, T: str](rpc: StreamRpc[P, A, E1, RpcMiddleware[MP, ME, Any], MT, T], /) -> StreamBound[G_co, RpcRequest[P], A, E1 | ME, MP, R_co | MT, T, H]The slot of rpc's handler: call it with the handler, which
gets the request (payload, headers, client, ...) and returns the
effect to run (for a stream RPC, a stream or a scoped queue). The
services rpc's middleware provides are removed from the
handler's requirements, and the middleware is required instead.
In a group that lists its tags, giving a handler to an RPC that
already has one, or is not in the group, is a pyright error.
| Parameter | Type | Description |
|---|---|---|
rpc |
@overload
def handle[P, S, E1, T: str](
self, rpc: Rpc[P, S, E1, Never, Never, T], /
) -> Bound[G_co, RpcRequest[P], S, E1, Never, R_co, T, H]: ...
@overload
def handle[P, S, E1, MP, ME, MT, T: str](
self, rpc: Rpc[P, S, E1, RpcMiddleware[MP, ME, Any], MT, T], /
) -> Bound[G_co, RpcRequest[P], S, E1 | ME, MP, R_co | MT, T, H]: ...
@overload
def handle[P, A, E1, T: str](
self, rpc: StreamRpc[P, A, E1, Never, Never, T], /
) -> StreamBound[G_co, RpcRequest[P], A, E1, Never, R_co, T, H]: ...
@overload
def handle[P, A, E1, MP, ME, MT, T: str](
self, rpc: StreamRpc[P, A, E1, RpcMiddleware[MP, ME, Any], MT, T], /
) -> StreamBound[G_co, RpcRequest[P], A, E1 | ME, MP, R_co | MT, T, H]: ...
def handle(self, rpc: AnyRpc, /) -> Any:
"""The slot of ``rpc``'s handler: call it with the handler, which
gets the request (payload, headers, client, ...) and returns the
effect to run (for a stream RPC, a stream or a scoped queue). The
services ``rpc``'s middleware provides are removed from the
handler's requirements, and the middleware is required instead.
In a group that lists its tags, giving a handler to an RPC that
already has one, or is not in the group, is a pyright error."""
if self.group.rpcs.get(rpc.tag) is not rpc:
raise ValueError(f"{rpc.tag!r} is not an RPC of {self.group.__name__}")
slot: type[_Slot] = StreamBound if rpc.is_stream else Bound
return cast("Any", slot(self, rpc))