refactor validation
[tiramisu.git] / tiramisu / option / baseoption.py
index d9eb6c2..4197250 100644 (file)
@@ -135,6 +135,9 @@ class Base(StorageBase):
                                      list(set_forbidden_properties)))
         StorageBase.__init__(self, name, _multi, warnings_only, doc, extra,
                              calc_properties, requires, properties)
+        if multi is not False and default is None:
+            default = []
+        self.impl_validate(default)
         self._set_default_values(default, default_multi)
         if callback is not False:
             self.impl_set_callback(callback, callback_params)
@@ -507,7 +510,7 @@ class Option(OnlyOption):
         if current_opt is undefined:
             current_opt = self
 
-        def val_validator(val):
+        def calculation_validator(val):
             validator, validator_params = self.impl_get_validator()
             if validator is not None:
                 if validator_params != {}:
@@ -524,7 +527,7 @@ class Option(OnlyOption):
                 else:
                     validator_params_ = {'': (val,)}
                 # Raise ValueError if not valid
-                carry_out_calculation(self, config=context,
+                carry_out_calculation(self, context=context,
                                       callback=validator,
                                       callback_params=validator_params_)
 
@@ -545,7 +548,7 @@ class Option(OnlyOption):
             warning = None
             try:
                 # valid with self._validator
-                val_validator(_value)
+                calculation_validator(_value)
                 # if not context launch consistency validation
                 if context is not undefined:
                     descr._valid_consistency(current_opt, _value, context,
@@ -721,6 +724,7 @@ class Option(OnlyOption):
                                          None, all_cons_opts, warnings_only,
                                          transitive)
         self._add_consistency(func, all_cons_opts, params)
+        #re validate default value when add consistency
         self.impl_validate(self.impl_getdefault())
 
     def _cons_not_equal(self, opts, vals, warnings_only):