An RPC with a payload P, succeeding with S or failing with
E, wrapped by the middleware M (MT repeats it, so handlers
can read both what it provides and its tag). Tag is its tag, a
Literal when make is given one, so a group listing its tags can
check its handlers.
Functions#
__init__#
__init__(tag, payload_schema, success_schema, error_schema, defect_schema, annotations=Context.empty(), middlewares=()) -> None| Parameter | Type | Description |
|---|---|---|
tag | str | |
payload_schema | Top | |
success_schema | Top | |
error_schema | Top | |
defect_schema | Top | |
annotations | Context[Any] = Context.empty() | |
middlewares | tuple[AnyMiddleware, ...] = () |
middleware#
middleware[T: RpcMiddleware[Any, Any, Any]](middleware) -> Rpc[P_co, S_co, E_co, M_co | T, MT_co | T, Tag_co]This RPC wrapped by middleware: its handler may fail with the
middleware's error and needs what it provides; a client may fail
with it too.
| Parameter | Type | Description |
|---|---|---|
middleware | type[T] |
Returns Rpc[P_co, S_co, E_co, M_co | T, MT_co | T, Tag_co]
def middleware[T: RpcMiddleware[Any, Any, Any]](
self, middleware: type[T], /
) -> Rpc[P_co, S_co, E_co, M_co | T, MT_co | T, Tag_co]:
"""This RPC wrapped by ``middleware``: its handler may fail with the
middleware's error and needs what it provides; a client may fail
with it too."""
return self.with_middleware(middleware)set_success#
set_success[S1](schema) -> Rpc[P_co, S1, E_co, M_co, MT_co, Tag_co]| Parameter | Type | Description |
|---|---|---|
schema | Codec[S1, Any, Never, Never] |
Returns Rpc[P_co, S1, E_co, M_co, MT_co, Tag_co]
def set_success[S1](
self, schema: Codec[S1, Any, Never, Never], /
) -> Rpc[P_co, S1, E_co, M_co, MT_co, Tag_co]:
return replace(self, success_schema=schema.__codec__()) # pyright: ignore[reportReturnType]set_error#
set_error[E1](schema) -> Rpc[P_co, S_co, E1, M_co, MT_co, Tag_co]| Parameter | Type | Description |
|---|---|---|
schema | Codec[E1, Any, Never, Never] |
Returns Rpc[P_co, S_co, E1, M_co, MT_co, Tag_co]
def set_error[E1](
self, schema: Codec[E1, Any, Never, Never], /
) -> Rpc[P_co, S_co, E1, M_co, MT_co, Tag_co]:
return replace(self, error_schema=schema.__codec__()) # pyright: ignore[reportReturnType]set_payload#
set_payload[P1](schema) -> Rpc[P1, S_co, E_co, M_co, MT_co, Tag_co]| Parameter | Type | Description |
|---|---|---|
schema | Codec[P1, Any, Never, Never] |
Returns Rpc[P1, S_co, E_co, M_co, MT_co, Tag_co]
def set_payload[P1](
self, schema: Codec[P1, Any, Never, Never], /
) -> Rpc[P1, S_co, E_co, M_co, MT_co, Tag_co]:
return replace(self, payload_schema=schema.__codec__()) # pyright: ignore[reportReturnType]prefix#
prefix(prefix) -> Rpc[P_co, S_co, E_co, M_co, MT_co]This RPC with prefix before its tag (typed str: Python can't
join Literal types).
| Parameter | Type | Description |
|---|---|---|
prefix | str |
Returns Rpc[P_co, S_co, E_co, M_co, MT_co]
def prefix(self, prefix: str) -> Rpc[P_co, S_co, E_co, M_co, MT_co]:
"""This RPC with ``prefix`` before its tag (typed ``str``: Python can't
join ``Literal`` types)."""
return replace(self, tag=prefix + self.tag)annotate#
annotate[A, T](tag, value) -> Self| Parameter | Type | Description |
|---|---|---|
tag | TagLike[A, T] | |
value | A |
Returns Self
def annotate[A, T](self, tag: TagLike[A, T], value: A) -> Self:
return replace(self, annotations=self.annotations.add(tag, value))annotate_merge#
annotate_merge(annotations) -> Self| Parameter | Type | Description |
|---|---|---|
annotations | Context[Any] |
Returns Self
def annotate_merge(self, annotations: Context[Any]) -> Self:
return replace(self, annotations=self.annotations.merge(annotations))with_middleware#
with_middleware(middleware) -> SelfThis RPC wrapped by middleware (untyped: middleware types it).
| Parameter | Type | Description |
|---|---|---|
middleware | AnyMiddleware |
Returns Self
def with_middleware(self, middleware: AnyMiddleware) -> Self:
"""This RPC wrapped by ``middleware`` (untyped: ``middleware`` types it)."""
if middleware in self.middlewares:
return self
return replace(self, middlewares=(*self.middlewares, middleware))pipe#
pipe[B](f) -> B| Parameter | Type | Description |
|---|---|---|
f | Callable[[Self], B] |
Returns B
def pipe[B](self, f: Callable[[Self], B], /) -> B:
return f(self)