diff --git a/IPython/utils/importstring.py b/IPython/utils/importstring.py index 8653d71..c8e1840 100644 --- a/IPython/utils/importstring.py +++ b/IPython/utils/importstring.py @@ -1,22 +1,11 @@ # encoding: utf-8 """ A simple utility to import something by its string name. - -Authors: - -* Brian Granger """ -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. -#----------------------------------------------------------------------------- -# Functions and classes -#----------------------------------------------------------------------------- def import_item(name): """Import and return ``bar`` given the string ``foo.bar``. @@ -41,8 +30,8 @@ def import_item(name): package, obj = parts module = __import__(package, fromlist=[obj]) try: - pak = module.__dict__[obj] - except KeyError: + pak = getattr(module, obj) + except AttributeError: raise ImportError('No module named %s' % obj) return pak else: diff --git a/IPython/utils/shimmodule.py b/IPython/utils/shimmodule.py index d9ac634..9b91f27 100644 --- a/IPython/utils/shimmodule.py +++ b/IPython/utils/shimmodule.py @@ -15,7 +15,7 @@ class ShimModule(types.ModuleType): # Use the equivalent of import_item(name), see below name = "%s.%s" % (self._mirror, key) - # NOTE: the code below is copied *verbatim* from + # NOTE: the code below was copied *verbatim* from # importstring.import_item. For some very strange reason that makes no # sense to me, if we call it *as a function*, it doesn't work. This # has something to do with the deep bowels of the import machinery and @@ -33,11 +33,7 @@ class ShimModule(types.ModuleType): # called with 'foo.bar....' package, obj = parts module = __import__(package, fromlist=[obj]) - try: - pak = module.__dict__[obj] - except KeyError: - raise AttributeError(obj) - return pak + return getattr(module, obj) else: # called with un-dotted string return __import__(parts[0])