Skip to content

Commit e9a65ea

Browse files
committed
Merge pull request ipython#126 from rmorshea/notify_change_by_dict
only pass a change dict to `_notify_change`
2 parents 4abfc2d + c3d7886 commit e9a65ea

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

traitlets/config/configurable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def update_config(self, config):
186186
# merge new config
187187
self.config.merge(config)
188188
# unconditionally notify trait change, which triggers load of new config
189-
self._notify_change('config', 'trait_change', {
189+
self._notify_change({
190190
'name': 'config',
191191
'old': oldconfig,
192192
'new': self.config,

traitlets/tests/test_traitlets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def change_dict(*ordered_values):
3737

3838
class HasTraitsStub(HasTraits):
3939

40-
def _notify_change(self, name, type, change):
40+
def _notify_change(self, change):
4141
self._notify_name = change['name']
4242
self._notify_old = change['old']
4343
self._notify_new = change['new']

traitlets/traitlets.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,9 @@ def compress(past_changes, change):
934934
past_changes.append(change)
935935
return past_changes
936936

937-
def hold(*a):
938-
cache[a[0]] = compress(cache.get(a[0]), a[2])
937+
def hold(change):
938+
name = change['name']
939+
cache[name] = compress(cache.get(name), change)
939940

940941
try:
941942
# Replace _notify_change with `hold`, caching and compressing
@@ -950,7 +951,7 @@ def hold(*a):
950951
setattr(self, name, value)
951952
except TraitError as e:
952953
# Roll back in case of TraitError during final cross validation.
953-
self._notify_change = lambda *x: None
954+
self._notify_change = lambda x: None
954955
for name, changes in cache.items():
955956
for change in changes[::-1]:
956957
# TODO: Separate in a rollback function per notification type.
@@ -975,18 +976,20 @@ def hold(*a):
975976
# trigger delayed notifications
976977
for changes in cache.values():
977978
for change in changes:
978-
self._notify_change(change['name'], change['type'], change)
979+
self._notify_change(change)
979980

980981
def _notify_trait(self, name, old_value, new_value):
981-
self._notify_change(name, 'change', {
982+
self._notify_change({
982983
'name': name,
983984
'old': old_value,
984985
'new': new_value,
985986
'owner': self,
986987
'type': 'change',
987988
})
988989

989-
def _notify_change(self, name, type, change):
990+
def _notify_change(self, change):
991+
name, type = change['name'], change['type']
992+
990993
callables = []
991994
callables.extend(self._trait_notifiers.get(name, {}).get(type, []))
992995
callables.extend(self._trait_notifiers.get(name, {}).get(All, []))

0 commit comments

Comments
 (0)