remove validate_calculator

This commit is contained in:
Emmanuel Garette 2018-04-16 19:51:13 +02:00
parent 38509aeb4b
commit 8b82e393fe
4 changed files with 20 additions and 37 deletions

View File

@ -19,14 +19,14 @@ class Params:
__slots__ = ('args', 'kwargs') __slots__ = ('args', 'kwargs')
def __init__(self, args=None, kwargs=None): def __init__(self, args=None, kwargs=None):
if args is None: if args is None:
args = [] args = tuple()
if kwargs is None: if kwargs is None:
kwargs = {} kwargs = {}
if isinstance(args, Param): if isinstance(args, Param):
args = (args,) args = (args,)
else: else:
if not isinstance(args, tuple): if not isinstance(args, tuple):
raise ValueError(_('args in params must be a list')) raise ValueError(_('args in params must be a tuple'))
for arg in args: for arg in args:
if not isinstance(arg, Param): if not isinstance(arg, Param):
raise ValueError(_('arg in params must be a Param')) raise ValueError(_('arg in params must be a Param'))

View File

@ -50,25 +50,6 @@ def valid_name(name):
not name.startswith('cfgimpl_') not name.startswith('cfgimpl_')
def validate_calculator(callback,
callback_params,
type_,
callbackoption):
"""validate function and parameter set for callback, validation, ...
"""
if not isinstance(callback, FunctionType):
raise ValueError(_('{0} must be a function').format(type_))
if callback_params is not None:
if not isinstance(callback_params, Params):
raise ValueError(_('{0}_params must be a params').format(type_))
for param in chain(callback_params.args, callback_params.kwargs.values()):
if isinstance(param, ParamContext):
callbackoption._has_calc_context = True
elif isinstance(param, ParamOption):
param.option._add_dependency(callbackoption)
callbackoption._has_dependency = True
#____________________________________________________________ #____________________________________________________________
# #
class Base(object): class Base(object):
@ -169,10 +150,22 @@ class Base(object):
def _build_calculator_params(self, def _build_calculator_params(self,
calculator, calculator,
calculator_params, calculator_params,
type_,
add_value=False): add_value=False):
""" """
:add_value: add value as first argument for validator :add_value: add value as first argument for validator
""" """
if not isinstance(calculator, FunctionType):
raise ValueError(_('{0} must be a function').format(type_))
if calculator_params is not None:
if not isinstance(calculator_params, Params):
raise ValueError(_('{0}_params must be a params').format(type_))
for param in chain(calculator_params.args, calculator_params.kwargs.values()):
if isinstance(param, ParamContext):
self._has_calc_context = True
elif isinstance(param, ParamOption):
param.option._add_dependency(self)
self._has_dependency = True
is_multi = self.impl_is_dynoptiondescription() or self.impl_is_multi() is_multi = self.impl_is_dynoptiondescription() or self.impl_is_multi()
func_args, func_kwargs, func_positional, func_keyword = self._get_function_args(calculator) func_args, func_kwargs, func_positional, func_keyword = self._get_function_args(calculator)
calculator_args, calculator_kwargs = self._get_parameters_args(calculator_params, add_value) calculator_args, calculator_kwargs = self._get_parameters_args(calculator_params, add_value)
@ -272,12 +265,9 @@ class Base(object):
self._validate_calculator(callback, self._validate_calculator(callback,
callback_params) callback_params)
if callback is not None: if callback is not None:
validate_calculator(callback,
callback_params,
'callback',
self)
callback_params = self._build_calculator_params(callback, callback_params = self._build_calculator_params(callback,
callback_params) callback_params,
'callback')
# first part is validator # first part is validator
val = getattr(self, '_val_call', (None,))[0] val = getattr(self, '_val_call', (None,))[0]
if callback_params == {}: if callback_params == {}:

View File

@ -22,7 +22,6 @@ from types import FunctionType
from ..setting import undefined from ..setting import undefined
from ..i18n import _ from ..i18n import _
from .baseoption import validate_calculator
from .option import Option from .option import Option
from ..autolib import carry_out_calculation from ..autolib import carry_out_calculation
from ..error import ConfigError, display_list from ..error import ConfigError, display_list
@ -56,12 +55,9 @@ class ChoiceOption(Option):
:param values: is a list of values the option can possibly take :param values: is a list of values the option can possibly take
""" """
if isinstance(values, FunctionType): if isinstance(values, FunctionType):
validate_calculator(values,
values_params,
'values',
self)
values_params = self._build_calculator_params(values, values_params = self._build_calculator_params(values,
values_params) values_params,
'values')
if values_params != {}: if values_params != {}:
self._choice_values_params = values_params self._choice_values_params = values_params
else: else:

View File

@ -22,7 +22,7 @@
import warnings import warnings
import weakref import weakref
from .baseoption import OnlyOption, submulti, validate_calculator, STATIC_TUPLE from .baseoption import OnlyOption, submulti, STATIC_TUPLE
from .symlinkoption import DynSymLinkOption from .symlinkoption import DynSymLinkOption
from ..i18n import _ from ..i18n import _
from ..setting import log, undefined, debug from ..setting import log, undefined, debug
@ -103,12 +103,9 @@ class Option(OnlyOption):
properties=properties, properties=properties,
is_multi=is_multi) is_multi=is_multi)
if validator is not None: if validator is not None:
validate_calculator(validator,
validator_params,
'validator',
self)
validator_params = self._build_calculator_params(validator, validator_params = self._build_calculator_params(validator,
validator_params, validator_params,
'validator',
add_value=True) add_value=True)
if validator_params == {}: if validator_params == {}:
val_call = (validator,) val_call = (validator,)