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 d0fe0c7d4189190be6ab80e917ae911ef5fd67c6..05e89b379ef1995fa0217e43067e347e63edb592 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 0d1d14f1fe62b780c3f1bf4656c16d5a91bc92dc..be5391ba662d944ba85be98d7682909161e51916 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