From 087cbdd4292c5fa1b480d12b752fcd493e5545c7 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 28 Nov 2021 12:48:26 -0500 Subject: [PATCH] Fix type annots in resource cacher internals --- tractor/trionics/_mngrs.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tractor/trionics/_mngrs.py b/tractor/trionics/_mngrs.py index 29be8322a..fff5a50d2 100644 --- a/tractor/trionics/_mngrs.py +++ b/tractor/trionics/_mngrs.py @@ -7,6 +7,7 @@ Any, AsyncContextManager, AsyncGenerator, + AsyncIterator, Hashable, Optional, Sequence, @@ -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 @@ -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 @@ -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)