Skip to content

Commit

Permalink
Fix type annots in resource cacher internals
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Dec 10, 2021
1 parent 7599ba5 commit 0bd1be5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tractor/trionics/_mngrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Any,
AsyncContextManager,
AsyncGenerator,
AsyncIterator,
Hashable,
Optional,
Sequence,
Expand Down Expand Up @@ -106,7 +107,7 @@ class cache:
values: dict[Any, Any] = {}
resources: dict[
int,
Optional[tuple[trio.Nursery, trio.Event]]
tuple[trio.Nursery, trio.Event]
] = {}
no_more_users: Optional[trio.Event] = None

Expand Down Expand Up @@ -137,7 +138,7 @@ async def maybe_open_context(
key: Hashable,
mngr: AsyncContextManager[T],

) -> (bool, T):
) -> AsyncIterator[tuple[bool, T]]:
'''
Maybe open a context manager if there is not already a cached
version for the provided ``key``. Return the cached instance on
Expand Down Expand Up @@ -170,9 +171,7 @@ async def maybe_open_context(
service_n = current_actor()._service_n

# TODO: does this need to be a tractor "root nursery"?
ln = cache.resources.get(ctx_key)
assert not ln

assert not cache.resources.get(ctx_key), f'Resource exists? {ctx_key}'
ln, _ = cache.resources[ctx_key] = (service_n, trio.Event())

value = await ln.start(cache.run_ctx, mngr, key)
Expand Down

0 comments on commit 0bd1be5

Please sign in to comment.