From 37cdd91f5de624acec9fbf7caa8d33c37ad920a1 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 25 May 2023 10:21:46 +1000 Subject: [PATCH] fix(nodes): use forward declarations for InvocationServices Also use `TYPE_CHECKING` to get IDE hints. --- invokeai/app/services/invocation_services.py | 60 ++++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/invokeai/app/services/invocation_services.py b/invokeai/app/services/invocation_services.py index bcbe95a41f..1f910253e5 100644 --- a/invokeai/app/services/invocation_services.py +++ b/invokeai/app/services/invocation_services.py @@ -1,18 +1,17 @@ # Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team +from __future__ import annotations from typing import TYPE_CHECKING -from logging import Logger - -from invokeai.app.services.images import ImageService -from invokeai.backend import ModelManager -from .events import EventServiceBase -from .latent_storage import LatentsStorageBase -from .restoration_services import RestorationServices -from .invocation_queue import InvocationQueueABC -from .item_storage import ItemStorageABC -from .config import InvokeAISettings - if TYPE_CHECKING: + from logging import Logger + from invokeai.app.services.images import ImageService + from invokeai.backend import ModelManager + from invokeai.app.services.events import EventServiceBase + from invokeai.app.services.latent_storage import LatentsStorageBase + from invokeai.app.services.restoration_services import RestorationServices + from invokeai.app.services.invocation_queue import InvocationQueueABC + from invokeai.app.services.item_storage import ItemStorageABC + from invokeai.app.services.config import InvokeAISettings from invokeai.app.services.graph import GraphExecutionState, LibraryGraph from invokeai.app.services.invoker import InvocationProcessorABC @@ -20,32 +19,33 @@ if TYPE_CHECKING: class InvocationServices: """Services that can be used by invocations""" - events: EventServiceBase - latents: LatentsStorageBase - queue: InvocationQueueABC - model_manager: ModelManager - restoration: RestorationServices - configuration: InvokeAISettings - images: ImageService + # TODO: Just forward-declared everything due to circular dependencies. Fix structure. + events: "EventServiceBase" + latents: "LatentsStorageBase" + queue: "InvocationQueueABC" + model_manager: "ModelManager" + restoration: "RestorationServices" + configuration: "InvokeAISettings" + images: "ImageService" # NOTE: we must forward-declare any types that include invocations, since invocations can use services - graph_library: ItemStorageABC["LibraryGraph"] - graph_execution_manager: ItemStorageABC["GraphExecutionState"] + graph_library: "ItemStorageABC"["LibraryGraph"] + graph_execution_manager: "ItemStorageABC"["GraphExecutionState"] processor: "InvocationProcessorABC" def __init__( self, - model_manager: ModelManager, - events: EventServiceBase, - logger: Logger, - latents: LatentsStorageBase, - images: ImageService, - queue: InvocationQueueABC, - graph_library: ItemStorageABC["LibraryGraph"], - graph_execution_manager: ItemStorageABC["GraphExecutionState"], + model_manager: "ModelManager", + events: "EventServiceBase", + logger: "Logger", + latents: "LatentsStorageBase", + images: "ImageService", + queue: "InvocationQueueABC", + graph_library: "ItemStorageABC"["LibraryGraph"], + graph_execution_manager: "ItemStorageABC"["GraphExecutionState"], processor: "InvocationProcessorABC", - restoration: RestorationServices, - configuration: InvokeAISettings = None, + restoration: "RestorationServices", + configuration: "InvokeAISettings", ): self.model_manager = model_manager self.events = events