Skip to content

Commit 920e544

Browse files
committed
simplify old value store for forced callbacks
1 parent 9aca443 commit 920e544

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed

lib/matplotlib/traitlets.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,11 @@
2525
import contextlib
2626

2727

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-
6028
class PrivateMethodMixin(object):
6129

6230
def __new__(cls, *args, **kwargs):
6331
inst = super(PrivateMethodMixin,cls).__new__(cls, *args, **kwargs)
64-
inst._trait_values = exdict(inst._trait_values)
32+
inst._stored_trait_values = {}
6533
return inst
6634

6735
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):
7341

7442
new = self._trait_values[name]
7543
try:
76-
old = self._trait_values.ex[name]
44+
old = self._stored_trait_values[name]
7745
except KeyError:
7846
trait = getattr(self.__class__, name)
7947
old = trait.default_value
@@ -89,6 +57,8 @@ def private(self, name, value=Undefined):
8957
trait = self._retrieve_trait(name)
9058

9159
if value is not Undefined:
60+
stored = self._stored_trait_values
61+
stored[name] = self.private(name)
9262
self._cross_validation_lock = True
9363
_notify_trait = self._notify_trait
9464
self._notify_trait = lambda *a: None

0 commit comments

Comments
 (0)