diff --git a/IPython/core/application.py b/IPython/core/application.py index cf26a31..918211b 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -25,7 +25,7 @@ from IPython.core import release, crashhandler from IPython.core.profiledir import ProfileDir, ProfileDirError from IPython.utils.path import get_ipython_dir, get_ipython_package_dir, ensure_dir_exists from IPython.utils import py3compat -from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, Set, Instance +from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, Set, Instance, Undefined if os.name == 'nt': programdata = os.environ.get('PROGRAMDATA', None) @@ -215,7 +215,7 @@ class BaseIPythonApplication(Application): return crashhandler.crash_handler_lite(etype, evalue, tb) def _ipython_dir_changed(self, name, old, new): - if old is not None: + if old is not None and old is not Undefined: str_old = py3compat.cast_bytes_py2(os.path.abspath(old), sys.getfilesystemencoding() ) diff --git a/IPython/utils/traitlets.py b/IPython/utils/traitlets.py index cf9016f..e1a0ca2 100644 --- a/IPython/utils/traitlets.py +++ b/IPython/utils/traitlets.py @@ -622,6 +622,8 @@ class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)): for name in cache: if cache[name][1] is not Undefined: setattr(self, name, cache[name][1]) + else: + delattr(self, name) notifications = {} raise e finally: @@ -633,10 +635,9 @@ class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)): # remove the redundant value from __dict__ # (only used to preserve pickleability on Python < 3.4) self.__dict__.pop('_notify_trait', None) - # trigger delayed notifications - for name in notifications: - self._notify_trait(*(notifications[name])) + for v in dict(cache, **notifications).values(): + self._notify_trait(*v) def _notify_trait(self, name, old_value, new_value):