25
25
import contextlib
26
26
27
27
28
- class exdict (dict ):
29
-
30
- def __init__ (self , * args , ** kwargs ):
31
- super (exdict , self ).__init__ (* args , ** kwargs )
32
- self ._memory = dict ()
33
-
34
- def __setitem__ (self , key , new ):
35
- try :
36
- old = self [key ]
37
- if old != new :
38
- self ._memory [key ] = old
39
- except KeyError :
40
- pass
41
- super (exdict , self ).__setitem__ (key , new )
42
-
43
- def update (self , * args , ** kwargs ):
44
- if len (args ) > 1 :
45
- raise TypeError ("update expected at most 1 arguments, got %d" % len (args ))
46
- other = dict (* args , ** kwargs )
47
- for key in other :
48
- self [key ] = other [key ]
49
-
50
- def setdefault (self , key , value = None ):
51
- if key not in self :
52
- self [key ] = value
53
- return self [key ]
54
-
55
- @property
56
- def ex (self ):
57
- return self ._memory .copy ()
58
-
59
-
60
28
class PrivateMethodMixin (object ):
61
29
62
30
def __new__ (cls , * args , ** kwargs ):
63
31
inst = super (PrivateMethodMixin ,cls ).__new__ (cls , * args , ** kwargs )
64
- inst ._trait_values = exdict ( inst . _trait_values )
32
+ inst ._stored_trait_values = {}
65
33
return inst
66
34
67
35
def force_callbacks (self , name , cross_validate = True , notify_trait = True ):
@@ -73,7 +41,7 @@ def force_callbacks(self, name, cross_validate=True, notify_trait=True):
73
41
74
42
new = self ._trait_values [name ]
75
43
try :
76
- old = self ._trait_values . ex [name ]
44
+ old = self ._stored_trait_values [name ]
77
45
except KeyError :
78
46
trait = getattr (self .__class__ , name )
79
47
old = trait .default_value
@@ -89,6 +57,8 @@ def private(self, name, value=Undefined):
89
57
trait = self ._retrieve_trait (name )
90
58
91
59
if value is not Undefined :
60
+ stored = self ._stored_trait_values
61
+ stored [name ] = self .private (name )
92
62
self ._cross_validation_lock = True
93
63
_notify_trait = self ._notify_trait
94
64
self ._notify_trait = lambda * a : None
0 commit comments