from typing import Any from pydantic_forms.validators import Choice class CustomerNotFoundError(Exception): """Exception raised when a customer is not found.""" pass def all_customers() -> list[dict]: return [ { "id": "8f0df561-ce9d-4d9c-89a8-7953d3ffc961", "name": "GÉANT", }, ] def get_customer_by_name(name: str) -> dict[str, Any]: for customer in all_customers(): if customer["name"] == name: return customer raise CustomerNotFoundError(f"Customer {name} not found") def customer_selector() -> Choice: customers = {} for customer in all_customers(): customers[customer["id"]] = customer["name"] return Choice("Select a customer", zip(customers.keys(), customers.items())) # type: ignore[arg-type]