we can pickle object
[tiramisu.git] / tiramisu / option / baseoption.py
index 25c5e11..b3720eb 100644 (file)
@@ -19,7 +19,7 @@
 # the whole pypy projet is under MIT licence
 # ____________________________________________________________
 import re
-from copy import copy, deepcopy
+from copy import copy
 from types import FunctionType
 import warnings
 
@@ -276,16 +276,15 @@ class BaseOption(Base):
             # remove variable if save variable converted
             # in _state_xxxx variable
             if '_state' + slot not in slots:
-                if slot.startswith('_state'):
-                    # should exists
-                    states[slot] = getattr(self, slot)
-                    # remove _state_xxx variable
-                    self.__delattr__(slot)
-                else:
-                    try:
+                try:
+                    if slot.startswith('_state'):
                         states[slot] = getattr(self, slot)
-                    except AttributeError:
-                        pass
+                        # remove _state_xxx variable
+                        self.__delattr__(slot)
+                    else:
+                        states[slot] = getattr(self, slot)
+                except AttributeError:
+                    pass
         if not stated:
             del(states['_stated'])
         return states
@@ -330,7 +329,8 @@ class BaseOption(Base):
         propertie or "read_only" property)
         """
         if name not in ('_option', '_is_build_cache') \
-                and not isinstance(value, tuple):
+                and not isinstance(value, tuple) and \
+                not name.startswith('_state'):
             is_readonly = False
             # never change _name
             if name == '_name':
@@ -669,14 +669,20 @@ class Option(OnlyOption):
     def _impl_convert_callbacks(self, descr, load=False):
         if not load and self._callback is None:
             self._state_callback = None
+            self._state_callback_params = None
         elif load and self._state_callback is None:
             self._callback = None
+            self._callback_params = None
             del(self._state_callback)
+            del(self._state_callback_params)
         else:
             if load:
-                callback, callback_params = self._state_callback
+                callback = self._state_callback
+                callback_params = self._state_callback_params
             else:
-                callback, callback_params = self._callback
+                callback = self._callback
+                callback_params = self._callback_params
+                self._state_callback_params = None
             if callback_params is not None:
                 cllbck_prms = {}
                 for key, values in callback_params.items():
@@ -696,9 +702,12 @@ class Option(OnlyOption):
 
             if load:
                 del(self._state_callback)
-                self._callback = (callback, cllbck_prms)
+                del(self._state_callback_params)
+                self._callback = callback
+                self._callback_params = cllbck_prms
             else:
-                self._state_callback = (callback, cllbck_prms)
+                self._state_callback = callback
+                self._state_callback_params = cllbck_prms
 
     # serialize/unserialize
     def _impl_convert_consistencies(self, descr, load=False):
@@ -834,7 +843,7 @@ def validate_requires_arg(requires, name):
 
 class SymLinkOption(OnlyOption):
     #FIXME : et avec sqlalchemy ca marche vraiment ?
-    __slots__ = ('_opt',)
+    __slots__ = ('_opt', '_state_opt')
     #not return _opt consistencies
     #_consistencies = None