From 5d411e446a09c41a23b5b583a8427e5a6490a1c0 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 23 Apr 2024 17:21:05 +1000 Subject: [PATCH] tidy(config): use a type alias for the migration function --- invokeai/app/services/config/config_migrate.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/invokeai/app/services/config/config_migrate.py b/invokeai/app/services/config/config_migrate.py index 3da734b2d9..6cdbca7558 100644 --- a/invokeai/app/services/config/config_migrate.py +++ b/invokeai/app/services/config/config_migrate.py @@ -10,6 +10,7 @@ from typing import Any, Callable, List, TypeAlias from packaging.version import Version AppConfigDict: TypeAlias = dict[str, Any] +MigrationFunction: TypeAlias = Callable[[AppConfigDict], AppConfigDict] @dataclass @@ -18,7 +19,7 @@ class MigrationEntry: from_version: Version to_version: Version - function: Callable[[AppConfigDict], AppConfigDict] + function: MigrationFunction class ConfigMigrator: @@ -31,10 +32,10 @@ class ConfigMigrator: cls, from_version: str, to_version: str, - ) -> Callable[[Callable[[AppConfigDict], AppConfigDict]], Callable[[AppConfigDict], AppConfigDict]]: + ) -> Callable[[MigrationFunction], MigrationFunction]: """Define a decorator which registers the migration between two versions.""" - def decorator(function: Callable[[AppConfigDict], AppConfigDict]) -> Callable[[AppConfigDict], AppConfigDict]: + def decorator(function: MigrationFunction) -> MigrationFunction: if from_version in cls._migrations: raise ValueError( f"function {function.__name__} is trying to register a migration for version {str(from_version)}, but this migration has already been registered."