Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/toad/acp/agent_configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Typed ACP advertisements own their selection, publication and request behavior."""
from __future__ import annotations

Expand All @@ -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
Expand Down Expand Up @@ -116,12 +117,9 @@


@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]
Expand Down
2 changes: 1 addition & 1 deletion src/toad/forms/editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)):
Expand Down
Loading