diff --git a/src/asphalt/core/__init__.py b/src/asphalt/core/__init__.py index d95db659..299342fd 100644 --- a/src/asphalt/core/__init__.py +++ b/src/asphalt/core/__init__.py @@ -9,7 +9,6 @@ from ._concurrent import start_background_task_factory as start_background_task_factory from ._concurrent import start_service_task as start_service_task from ._context import Context as Context -from ._context import GeneratedResource as GeneratedResource from ._context import ResourceEvent as ResourceEvent from ._context import add_resource as add_resource from ._context import add_resource_factory as add_resource_factory diff --git a/src/asphalt/core/_context.py b/src/asphalt/core/_context.py index f5fd1de9..495046e0 100644 --- a/src/asphalt/core/_context.py +++ b/src/asphalt/core/_context.py @@ -421,16 +421,6 @@ def add_resource_factory( ) origin = get_origin(return_type_hint) - if origin is GeneratedResource: - args = get_args(return_type_hint) - if len(args) != 1: - raise ValueError( - f"GeneratedResource must specify exactly one parameter, got " - f"{len(args)}" - ) - - return_type_hint = args[0] - if origin is Union or ( sys.version_info >= (3, 10) and origin is stdlib_types.UnionType ): @@ -509,20 +499,13 @@ def get_resource_nowait( if key in ctx._resource_factories: # Call the factory callback to generate the resource factory = ctx._resource_factories[key] - retval = factory.value_or_factory() + resource = factory.value_or_factory() # Raise AsyncResourceError if the factory returns a coroutine object - if iscoroutine(retval): - retval.close() + if iscoroutine(resource): + resource.close() raise AsyncResourceError() - if isinstance(retval, GeneratedResource): - resource = retval.resource - if retval.teardown_callback is not None: - self.add_teardown_callback(retval.teardown_callback) - else: - resource = retval - # Store the generated resource in the context container = ResourceContainer( resource, factory.types, factory.name, factory.description, False @@ -606,16 +589,9 @@ async def get_resource( for ctx in self.context_chain: if key in ctx._resource_factories: factory = ctx._resource_factories[key] - retval = factory.value_or_factory() - if isawaitable(retval): - retval = await retval - - if isinstance(retval, GeneratedResource): - resource = retval.resource - if retval.teardown_callback is not None: - self.add_teardown_callback(retval.teardown_callback) - else: - resource = retval + resource = factory.value_or_factory() + if isawaitable(resource): + resource = await resource container = ResourceContainer( resource, factory.types, factory.name, factory.description, False