Refine type annots in `_discovery` and `_runtime`

- Add `LocalPortal` union to `query_actor()` return
  type and `reg_portal` var annotation since the
  registrar yields a `LocalPortal` instance.
- Update docstring to note the `LocalPortal` case.
- Widen `.delete_addr()` `addr` param to accept
  `list[str|int]` bc msgpack deserializes tuples as
  lists over IPC.
- Tighten `uid` annotation to `tuple[str, str]|None`.

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
multicast_revertable_streams
Gud Boi 2026-03-25 02:16:48 -04:00
parent b557ec20a7
commit e71eec07de
2 changed files with 7 additions and 6 deletions

View File

@ -153,7 +153,7 @@ async def query_actor(
regaddr: UnwrappedAddress|None = None,
) -> AsyncGenerator[
tuple[UnwrappedAddress|None, Portal|None],
tuple[UnwrappedAddress|None, Portal|LocalPortal|None],
None,
]:
'''
@ -163,8 +163,9 @@ async def query_actor(
Yields a `tuple` of `(addr, reg_portal)` where,
- `addr` is the transport protocol (socket) address or `None` if
no entry under that name exists,
- `reg_portal` is the `Portal` to the registrar used for the
lookup (or `None` when the peer was found locally via
- `reg_portal` is the `Portal` (or `LocalPortal` when the
current actor is the registrar) used for the lookup (or
`None` when the peer was found locally via
`get_peer_by_name()`).
'''
@ -183,7 +184,7 @@ async def query_actor(
yield maybe_peers[0].raddr, None
return
reg_portal: Portal
reg_portal: Portal|LocalPortal
regaddr: Address = wrap_address(regaddr) or actor.reg_addrs[0]
async with get_registry(regaddr) as reg_portal:
# TODO: return portals to all available actors - for now

View File

@ -2042,12 +2042,12 @@ class Arbiter(Actor):
async def delete_addr(
self,
addr: tuple[str, int|str],
addr: tuple[str, int|str]|list[str|int],
) -> tuple[str, str]|None:
# NOTE: `addr` arrives as a `list` over IPC
# (msgpack deserializes tuples -> lists) so
# coerce to `tuple` for the bidict hash lookup.
uid: tuple | None = self._registry.inverse.pop(
uid: tuple[str, str]|None = self._registry.inverse.pop(
tuple(addr),
None,
)