support slave with list has calculated value
authorEmmanuel Garette <egarette@cadoles.com>
Fri, 8 Apr 2016 14:21:50 +0000 (16:21 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Fri, 8 Apr 2016 14:21:50 +0000 (16:21 +0200)
tiramisu/autolib.py

index ffcdee8..6985a97 100644 (file)
@@ -137,6 +137,7 @@ def carry_out_calculation(option, context, callback, callback_params,
     tcparams = {}
     # if callback_params has a callback, launch several time calculate()
     master_slave = False
+    has_option = False
     # multi's option should have same value for all option
     if option._is_subdyn():
         tcparams['suffix'] = [(option.impl_getsuffix(), False)]
@@ -180,6 +181,7 @@ def carry_out_calculation(option, context, callback, callback_params,
                             raise value
                     # convert to list, not modifie this multi
                     if value.__class__.__name__ == 'Multi':
+                        has_option = True
                         value = list(value)
 
                     if opt.impl_is_master_slaves() and \
@@ -227,8 +229,15 @@ def carry_out_calculation(option, context, callback, callback_params,
         ret = calculate(callback, args, kwargs, returns_raise)
         if not option.impl_is_optiondescription() and callback_params != {} and isinstance(ret, list) and \
                 option.impl_is_master_slaves('slave'):
-            raise SlaveError(_("callback cannot return a list for a "
-                               "slave option ({0})").format(option.impl_getname()))
+            if not has_option and index not in [None, undefined]:
+                if index < len(ret):
+                    ret = ret[index]
+                else:
+                    #FIXME really?
+                    ret = None
+            else:
+                raise SlaveError(_("callback cannot return a list for a "
+                                   "slave option ({0})").format(option.impl_getname()))
         return ret