From a4047b2e687f830ace903fb0c94c41e56329578e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BBebrak?= <mzebrak@syncad.com> Date: Fri, 7 Mar 2025 14:47:50 +0100 Subject: [PATCH] Create ComposeFormResult typealias --- .../ui/forms/create_profile/create_profile_form.py | 11 ++--------- clive/__private/ui/forms/form.py | 12 ++++++------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/clive/__private/ui/forms/create_profile/create_profile_form.py b/clive/__private/ui/forms/create_profile/create_profile_form.py index d0fe0c7d41..05e89b379e 100644 --- a/clive/__private/ui/forms/create_profile/create_profile_form.py +++ b/clive/__private/ui/forms/create_profile/create_profile_form.py @@ -1,18 +1,11 @@ from __future__ import annotations -from typing import TYPE_CHECKING - from clive.__private.core.profile import Profile from clive.__private.ui.forms.create_profile.create_profile_form_screen import CreateProfileFormScreen from clive.__private.ui.forms.create_profile.new_key_alias_form_screen import NewKeyAliasFormScreen from clive.__private.ui.forms.create_profile.set_account_form_screen import SetAccountFormScreen from clive.__private.ui.forms.create_profile.welcome_form_screen import CreateProfileWelcomeFormScreen -from clive.__private.ui.forms.form import Form - -if TYPE_CHECKING: - from collections.abc import Iterator - - from clive.__private.ui.forms.form_screen import FormScreen +from clive.__private.ui.forms.form import ComposeFormResult, Form class CreateProfileForm(Form): @@ -23,7 +16,7 @@ class CreateProfileForm(Form): async def cleanup(self) -> None: await self.world.switch_profile(None) - def compose_form(self) -> Iterator[type[FormScreen]]: + def compose_form(self) -> ComposeFormResult: if not Profile.is_any_profile_saved(): yield CreateProfileWelcomeFormScreen yield CreateProfileFormScreen diff --git a/clive/__private/ui/forms/form.py b/clive/__private/ui/forms/form.py index 0d1d14f1fe..be5391ba66 100644 --- a/clive/__private/ui/forms/form.py +++ b/clive/__private/ui/forms/form.py @@ -2,20 +2,20 @@ from __future__ import annotations import inspect from abc import abstractmethod -from collections.abc import Callable, Iterator +from collections.abc import Callable from queue import Queue -from typing import TYPE_CHECKING, Any, cast +from typing import Any, Iterable, cast from clive.__private.core.commands.abc.command import Command from clive.__private.core.contextual import ContextualHolder from clive.__private.ui.clive_screen import CliveScreen from clive.__private.ui.forms.form_context import FormContextT, NoContext - -if TYPE_CHECKING: - from clive.__private.ui.forms.form_screen import FormScreen +from clive.__private.ui.forms.form_screen import FormScreen PostAction = Command | Callable[[], Any] +ComposeFormResult = Iterable[type[FormScreen[FormContextT]]] + class Form(ContextualHolder[FormContextT], CliveScreen[None]): MINIMUM_SCREEN_COUNT = 2 # Rationale: it makes no sense to have only one screen in the form @@ -29,7 +29,7 @@ class Form(ContextualHolder[FormContextT], CliveScreen[None]): super().__init__(self._build_context()) @abstractmethod - def compose_form(self) -> Iterator[type[FormScreen[FormContextT]]]: + def compose_form(self) -> ComposeFormResult[FormContextT]: """Yield screens types in the order they should be displayed.""" @property -- GitLab