Skip to content

Commit

Permalink
Merge pull request #42 from minrk/update-always-notify
Browse files Browse the repository at this point in the history
ensure update_config triggers _config_changed
  • Loading branch information
takluyver committed Jun 30, 2015
2 parents b69a22a + 3c46e85 commit 6b88929
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
10 changes: 0 additions & 10 deletions traitlets/config/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,6 @@ def print_version(self):
"""Print the version string."""
print(self.version)

def update_config(self, config):
"""Fire the traits events when the config is updated."""
# Save a copy of the current config.
newconfig = deepcopy(self.config)
# Merge the new config into the current one.
newconfig.merge(config)
# Save the combined config as self.config, which triggers the traits
# events.
self.config = newconfig

@catch_config_error
def initialize_subcommand(self, subc, argv=None):
"""Initialize a subcommand with argv."""
Expand Down
15 changes: 7 additions & 8 deletions traitlets/config/configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,13 @@ def _config_changed(self, name, old, new):
self._load_config(new, traits=traits, section_names=section_names)

def update_config(self, config):
"""Fire the traits events when the config is updated."""
# Save a copy of the current config.
newconfig = deepcopy(self.config)
# Merge the new config into the current one.
newconfig.merge(config)
# Save the combined config as self.config, which triggers the traits
# events.
self.config = newconfig
"""Update config and trigger reload of config via trait events"""
# Save a copy of the old config
oldconfig = deepcopy(self.config)
# merge new config
self.config.merge(config)
# unconditionally notify trait change, which triggers load of new config
self._notify_trait('config', oldconfig, self.config)

@classmethod
def class_get_help(cls, inst=None):
Expand Down
10 changes: 10 additions & 0 deletions traitlets/config/tests/test_configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ def test_update_twice(self):
m.update_config(c2)
self.assertEqual(m.a, 15)

def test_update_self(self):
"""update_config with same config object still triggers config_changed"""
c = Config()
c.MyConfigurable.a = 5
m = MyConfigurable(config=c)
self.assertEqual(m.a, 5)
c.MyConfigurable.a = 10
m.update_config(c)
self.assertEqual(m.a, 10)

def test_config_default(self):
class SomeSingleton(SingletonConfigurable):
pass
Expand Down

0 comments on commit 6b88929

Please sign in to comment.