From e1fef114654ccef4d990cb48ec5abe56641e7aa5 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 5 Oct 2020 21:16:41 +0200 Subject: [PATCH] refactor --- tiramisu/option/choiceoption.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tiramisu/option/choiceoption.py b/tiramisu/option/choiceoption.py index babf658..29e2f42 100644 --- a/tiramisu/option/choiceoption.py +++ b/tiramisu/option/choiceoption.py @@ -76,17 +76,18 @@ class ChoiceOption(Option): if isinstance(self._choice_values, Calculation): return values = self._choice_values - if values is not undefined and value not in values: - if len(values) == 1: - raise ValueError(_('only "{0}" is allowed' - '').format(values[0])) - raise ValueError(_('only {0} are allowed' - '').format(display_list(values, add_quote=True))) + self.validate_values(value, values) async def validate_with_option(self, value: Any, option_bag: OptionBag) -> None: values = await self.impl_get_values(option_bag) + self.validate_values(value, values) + + def validate_values(self, + value, + values, + ) -> None: if values is not undefined and value not in values: if len(values) == 1: raise ValueError(_('only "{0}" is allowed'