diff --git a/ChangeLog b/ChangeLog index 67fb6af..04b5161 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ Sun Apr 27 10:32:40 2014 +0200 Emmanuel Garette + * behavior change in ChoiceOption: + remove open_values, that no sens (no type validation is possible) if + you wan't something like open_values, please use a typed option and + add impl_(s|g)et_information to add proposed values and use it in your + code * add dynamic ChoiceOption: we can have dynamic ChoiceOption. Parameter values can be a function and as callback, we can add values_params diff --git a/test/test_config_api.py b/test/test_config_api.py index 979a1e8..488e7b8 100644 --- a/test/test_config_api.py +++ b/test/test_config_api.py @@ -268,7 +268,6 @@ def test_impl_getpaths(): def test_invalid_option(): raises(TypeError, "ChoiceOption('a', '', [1, 2])") raises(TypeError, "ChoiceOption('a', '', 1)") - raises(TypeError, "ChoiceOption('a', '', (1,), open_values='string')") raises(ValueError, "ChoiceOption('a', '', (1,), 3)") raises(ValueError, "FloatOption('a', '', 'string')") raises(ValueError, "UnicodeOption('a', '', 1)") diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 9aeb7d5..584d94b 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -41,7 +41,7 @@ class ChoiceOption(Option): def __init__(self, name, doc, values, default=None, values_params=None, default_multi=None, requires=None, multi=False, callback=None, callback_params=None, - open_values=False, validator=None, validator_params=None, + validator=None, validator_params=None, properties=None, warnings_only=False): """ :param values: is a list of values the option can possibly take @@ -51,11 +51,7 @@ class ChoiceOption(Option): elif not isinstance(values, tuple): raise TypeError(_('values must be a tuple or a function for {0}' ).format(name)) - if open_values not in (True, False): - raise TypeError(_('open_values must be a boolean for ' - '{0}').format(name)) - self._extra = {'_choice_open_values': open_values, - '_choice_values': values, + self._extra = {'_choice_values': values, '_choice_values_params': values_params} super(ChoiceOption, self).__init__(name, doc, default=default, default_multi=default_multi, @@ -83,14 +79,10 @@ class ChoiceOption(Option): '').format(self.impl_getname())) return values - def impl_is_openvalues(self): - return self._extra['_choice_open_values'] - def _validate(self, value, context=None): try: values = self.impl_get_values(context) - if not self.impl_is_openvalues() and \ - not value in values: + if not value in values: raise ValueError(_('value {0} is not permitted, ' 'only {1} is allowed' '').format(value,