GitHub

EntityHandlers

API reference for EntityHandlers.

The handlers of the entity G so far, needing R; H is the tags of the RPCs still without one, for an entity that lists its tags (Never once all have one, and for an entity that does not). Immutable: handle gives a new one.

Attributes

AttributeTypeDescription
entity= entity
by_tagMapping[str, EntityHandlerFn]

Functions

__init__

__init__(entity, by_tag) -> None
ParameterTypeDescription
entitytype[Entity[Any]]
by_tagMapping[str, EntityHandlerFn]
def __init__(self, entity: type[Entity[Any]], by_tag: Mapping[str, EntityHandlerFn]) -> None:
    self.entity = entity
    self._by_tag = dict(by_tag)

handle

handle[P, S, E1, T: str](rpc: Rpc[P, S, E1, Never, Never, T], /) -> Bound[G_co, Request[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, Request[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, Request[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, Request[P], A, E1 | ME, MP, R_co | MT, T, H]

The slot of rpc's handler: call it with the handler, which gets the entity Request and returns the effect to run (for a stream RPC, a stream or a scoped queue). In an entity that lists its tags, giving a handler to an RPC that already has one, or is not the entity's, is a pyright error.

ParameterTypeDescription
rpc
@overload
def handle[P, S, E1, T: str](
    self, rpc: Rpc[P, S, E1, Never, Never, T], /
) -> Bound[G_co, Request[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, Request[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, Request[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, Request[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 entity ``Request`` and returns the effect to run (for a
    stream RPC, a stream or a scoped queue). In an entity that lists its
    tags, giving a handler to an RPC that already has one, or is not the
    entity's, is a pyright error."""
    if rpc.tag not in self.entity.rpcs:
        raise ValueError(f"{rpc.tag!r} is not an RPC of the entity {self.entity.type}")
    slot: type[_Slot] = StreamBound if rpc.is_stream else Bound
    return cast("Any", slot(self, rpc.tag))

missing

missing() -> list[str]

The tags of the entity's RPCs without a handler.

Returns list[str]

def missing(self) -> list[str]:
    """The tags of the entity's RPCs without a handler."""
    return [tag for tag in self.entity.rpcs if tag not in self._by_tag]