remove unjustified open_values parameters in ChoiceOption
This commit is contained in:
parent
31fff062e1
commit
888446e4c5
|
@ -1,5 +1,10 @@
|
||||||
Sun Apr 27 10:32:40 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
|
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:
|
* add dynamic ChoiceOption:
|
||||||
we can have dynamic ChoiceOption. Parameter values can be a function
|
we can have dynamic ChoiceOption. Parameter values can be a function
|
||||||
and as callback, we can add values_params
|
and as callback, we can add values_params
|
||||||
|
|
|
@ -268,7 +268,6 @@ def test_impl_getpaths():
|
||||||
def test_invalid_option():
|
def test_invalid_option():
|
||||||
raises(TypeError, "ChoiceOption('a', '', [1, 2])")
|
raises(TypeError, "ChoiceOption('a', '', [1, 2])")
|
||||||
raises(TypeError, "ChoiceOption('a', '', 1)")
|
raises(TypeError, "ChoiceOption('a', '', 1)")
|
||||||
raises(TypeError, "ChoiceOption('a', '', (1,), open_values='string')")
|
|
||||||
raises(ValueError, "ChoiceOption('a', '', (1,), 3)")
|
raises(ValueError, "ChoiceOption('a', '', (1,), 3)")
|
||||||
raises(ValueError, "FloatOption('a', '', 'string')")
|
raises(ValueError, "FloatOption('a', '', 'string')")
|
||||||
raises(ValueError, "UnicodeOption('a', '', 1)")
|
raises(ValueError, "UnicodeOption('a', '', 1)")
|
||||||
|
|
|
@ -41,7 +41,7 @@ class ChoiceOption(Option):
|
||||||
def __init__(self, name, doc, values, default=None,
|
def __init__(self, name, doc, values, default=None,
|
||||||
values_params=None, default_multi=None, requires=None,
|
values_params=None, default_multi=None, requires=None,
|
||||||
multi=False, callback=None, callback_params=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):
|
properties=None, warnings_only=False):
|
||||||
"""
|
"""
|
||||||
:param values: is a list of values the option can possibly take
|
:param values: is a list of values the option can possibly take
|
||||||
|
@ -51,11 +51,7 @@ class ChoiceOption(Option):
|
||||||
elif not isinstance(values, tuple):
|
elif not isinstance(values, tuple):
|
||||||
raise TypeError(_('values must be a tuple or a function for {0}'
|
raise TypeError(_('values must be a tuple or a function for {0}'
|
||||||
).format(name))
|
).format(name))
|
||||||
if open_values not in (True, False):
|
self._extra = {'_choice_values': values,
|
||||||
raise TypeError(_('open_values must be a boolean for '
|
|
||||||
'{0}').format(name))
|
|
||||||
self._extra = {'_choice_open_values': open_values,
|
|
||||||
'_choice_values': values,
|
|
||||||
'_choice_values_params': values_params}
|
'_choice_values_params': values_params}
|
||||||
super(ChoiceOption, self).__init__(name, doc, default=default,
|
super(ChoiceOption, self).__init__(name, doc, default=default,
|
||||||
default_multi=default_multi,
|
default_multi=default_multi,
|
||||||
|
@ -83,14 +79,10 @@ class ChoiceOption(Option):
|
||||||
'').format(self.impl_getname()))
|
'').format(self.impl_getname()))
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def impl_is_openvalues(self):
|
|
||||||
return self._extra['_choice_open_values']
|
|
||||||
|
|
||||||
def _validate(self, value, context=None):
|
def _validate(self, value, context=None):
|
||||||
try:
|
try:
|
||||||
values = self.impl_get_values(context)
|
values = self.impl_get_values(context)
|
||||||
if not self.impl_is_openvalues() and \
|
if not value in values:
|
||||||
not value in values:
|
|
||||||
raise ValueError(_('value {0} is not permitted, '
|
raise ValueError(_('value {0} is not permitted, '
|
||||||
'only {1} is allowed'
|
'only {1} is allowed'
|
||||||
'').format(value,
|
'').format(value,
|
||||||
|
|
Loading…
Reference in New Issue