From 231647c8a592693dde7a6e2d8e2e69da8dad204e 2014-12-01 18:54:50 From: Thomas Kluyver Date: 2014-12-01 18:54:50 Subject: [PATCH] Don't calculate default value when setting traitlet for the first time --- diff --git a/IPython/core/application.py b/IPython/core/application.py index 87cd3eb..eb12377 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -199,11 +199,12 @@ class BaseIPythonApplication(Application): return crashhandler.crash_handler_lite(etype, evalue, tb) def _ipython_dir_changed(self, name, old, new): - str_old = py3compat.cast_bytes_py2(os.path.abspath(old), - sys.getfilesystemencoding() - ) - if str_old in sys.path: - sys.path.remove(str_old) + if old is not None: + str_old = py3compat.cast_bytes_py2(os.path.abspath(old), + sys.getfilesystemencoding() + ) + if str_old in sys.path: + sys.path.remove(str_old) str_path = py3compat.cast_bytes_py2(os.path.abspath(new), sys.getfilesystemencoding() ) diff --git a/IPython/kernel/zmq/pylab/config.py b/IPython/kernel/zmq/pylab/config.py index fe2c1a5..7a73685 100644 --- a/IPython/kernel/zmq/pylab/config.py +++ b/IPython/kernel/zmq/pylab/config.py @@ -13,6 +13,7 @@ This module does not import anything from matplotlib. # Imports #----------------------------------------------------------------------------- +from IPython.config import Config from IPython.config.configurable import SingletonConfigurable from IPython.utils.traitlets import ( Dict, Instance, CaselessStrEnum, Set, Bool, Int, TraitError, Unicode @@ -42,7 +43,7 @@ class InlineBackend(InlineBackendConfig): def _config_changed(self, name, old, new): # warn on change of renamed config section - if new.InlineBackendConfig != old.InlineBackendConfig: + if new.InlineBackendConfig != getattr(old, 'InlineBackendConfig', Config()): warn("InlineBackendConfig has been renamed to InlineBackend") super(InlineBackend, self)._config_changed(name, old, new) diff --git a/IPython/utils/traitlets.py b/IPython/utils/traitlets.py index b3db08d..8ec27cb 100644 --- a/IPython/utils/traitlets.py +++ b/IPython/utils/traitlets.py @@ -415,7 +415,11 @@ class TraitType(object): def __set__(self, obj, value): new_value = self._validate(obj, value) - old_value = self.__get__(obj) + try: + old_value = obj._trait_values[self.name] + except KeyError: + old_value = None + obj._trait_values[self.name] = new_value try: silent = bool(old_value == new_value)