Skip to content

Commit e71eec0

Browse files
committed
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
1 parent b557ec2 commit e71eec0

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

tractor/_discovery.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ async def query_actor(
153153
regaddr: UnwrappedAddress|None = None,
154154

155155
) -> AsyncGenerator[
156-
tuple[UnwrappedAddress|None, Portal|None],
156+
tuple[UnwrappedAddress|None, Portal|LocalPortal|None],
157157
None,
158158
]:
159159
'''
@@ -163,8 +163,9 @@ async def query_actor(
163163
Yields a `tuple` of `(addr, reg_portal)` where,
164164
- `addr` is the transport protocol (socket) address or `None` if
165165
no entry under that name exists,
166-
- `reg_portal` is the `Portal` to the registrar used for the
167-
lookup (or `None` when the peer was found locally via
166+
- `reg_portal` is the `Portal` (or `LocalPortal` when the
167+
current actor is the registrar) used for the lookup (or
168+
`None` when the peer was found locally via
168169
`get_peer_by_name()`).
169170
170171
'''
@@ -183,7 +184,7 @@ async def query_actor(
183184
yield maybe_peers[0].raddr, None
184185
return
185186

186-
reg_portal: Portal
187+
reg_portal: Portal|LocalPortal
187188
regaddr: Address = wrap_address(regaddr) or actor.reg_addrs[0]
188189
async with get_registry(regaddr) as reg_portal:
189190
# TODO: return portals to all available actors - for now

tractor/_runtime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,12 +2042,12 @@ async def unregister_actor(
20422042

20432043
async def delete_addr(
20442044
self,
2045-
addr: tuple[str, int|str],
2045+
addr: tuple[str, int|str]|list[str|int],
20462046
) -> tuple[str, str]|None:
20472047
# NOTE: `addr` arrives as a `list` over IPC
20482048
# (msgpack deserializes tuples -> lists) so
20492049
# coerce to `tuple` for the bidict hash lookup.
2050-
uid: tuple | None = self._registry.inverse.pop(
2050+
uid: tuple[str, str]|None = self._registry.inverse.pop(
20512051
tuple(addr),
20522052
None,
20532053
)

0 commit comments

Comments
 (0)