From c2bffc12eadae60386dbeb4cff6b9fc0f5853d71 Mon Sep 17 00:00:00 2001 From: Tristan Simas Date: Thu, 12 Nov 2026 16:57:14 -0500 Subject: [PATCH] Consume original choice labels and values in one pass --- src/toad/acp/agent_configuration.py | 12 +++++------- src/toad/forms/editors.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/toad/acp/agent_configuration.py b/src/toad/acp/agent_configuration.py index 40f4dca3c..800c312cd 100644 --- a/src/toad/acp/agent_configuration.py +++ b/src/toad/acp/agent_configuration.py @@ -16,8 +16,9 @@ from formbridge.forms.declared_fields import DeclaredMetadata from metaclass_registry.mro_dispatch import MroDispatch, handles from objectstate import ObjectState -from python_introspect import AnnotationChoices, FieldLabel +from python_introspect import FieldLabel +from python_introspect.choices import LabelledChoices from toad.acp.client_session import ClientSessionRequest from toad.core.configuration_events import ChangeConfiguration, ChangeModel from toad.core.events import ConfigurationChanged @@ -116,12 +117,9 @@ class AdvertisedSetting: @dataclass(frozen=True) -class AdvertisedChoices(AdvertisedSetting, AnnotationChoices, DeclaredMetadata): - def choices(self) -> tuple[object, ...]: - return tuple(choice.value for choice in self.setting.choices) - - def label(self, value: object) -> str: - return next(choice.name for choice in self.setting.choices if choice.value == value) +class AdvertisedChoices(AdvertisedSetting, LabelledChoices, DeclaredMetadata): + def labelled_choices(self) -> tuple[tuple[str, object], ...]: + return tuple((choice.name, choice.value) for choice in self.setting.choices) def declares(self): yield from type(self.setting).__mro__[:-1] diff --git a/src/toad/forms/editors.py b/src/toad/forms/editors.py index bc2e10330..e81549e53 100644 --- a/src/toad/forms/editors.py +++ b/src/toad/forms/editors.py @@ -286,7 +286,7 @@ def choices(self) -> AnnotationChoices: return choices def options(self) -> Iterable[tuple[str, object]]: - return ((self.choices.label(choice), choice) for choice in self.choices.choices()) + return self.choices.labelled_choices() class EnumEditor(SelectEditor, shows=(Enum,)):