better multi support

This commit is contained in:
egarette@silique.fr 2023-11-15 21:44:15 +01:00
parent 0b2f13404c
commit 4b052c3943

View file

@ -266,14 +266,13 @@ class Option(BaseOption):
option_bag: OptionBag, option_bag: OptionBag,
check_error: bool=True, check_error: bool=True,
loaded: bool=False, loaded: bool=False,
) -> None: ) -> bool:
"""Return True if value is really valid """Return True if value is really valid
If not validate or invalid return it returns False If not validate or invalid return it returns False
""" """
config_bag = option_bag.config_bag config_bag = option_bag.config_bag
force_index = option_bag.index force_index = option_bag.index
is_warnings_only = getattr(self, '_warnings_only', False) is_warnings_only = getattr(self, '_warnings_only', False)
if check_error and config_bag is not undefined and \ if check_error and config_bag is not undefined and \
not 'validator' in config_bag.properties: not 'validator' in config_bag.properties:
return False return False
@ -363,9 +362,9 @@ class Option(BaseOption):
calculation_validator(_value, calculation_validator(_value,
_index, _index,
) )
try:
val = value val = value
err_index = force_index err_index = force_index
try:
if not self.impl_is_multi(): if not self.impl_is_multi():
do_validation(val, None) do_validation(val, None)
elif force_index is not None: elif force_index is not None:
@ -385,8 +384,6 @@ class Option(BaseOption):
) )
elif isinstance(value, Calculation) and config_bag is undefined: elif isinstance(value, Calculation) and config_bag is undefined:
pass pass
elif not isinstance(value, list):
raise ValueError(_('which must be a list'))
elif self.impl_is_submulti(): elif self.impl_is_submulti():
for err_index, lval in enumerate(value): for err_index, lval in enumerate(value):
if isinstance(lval, Calculation): if isinstance(lval, Calculation):
@ -398,8 +395,10 @@ class Option(BaseOption):
do_validation(val, do_validation(val,
err_index) err_index)
_is_not_unique(lval, option_bag) _is_not_unique(lval, option_bag)
elif not isinstance(value, list):
raise ValueError(_('which must be a list'))
else: else:
# FIXME suboptimal, not several time is whole=True! # FIXME suboptimal, not several time for whole=True!
for err_index, val in enumerate(value): for err_index, val in enumerate(value):
do_validation(val, do_validation(val,
err_index, err_index,