remove unjustified open_values parameters in ChoiceOption

This commit is contained in:
Emmanuel Garette 2014-04-27 10:44:19 +02:00
parent 31fff062e1
commit 888446e4c5
3 changed files with 8 additions and 12 deletions

View File

@ -1,5 +1,10 @@
Sun Apr 27 10:32:40 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
* 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

View File

@ -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)")

View File

@ -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,