##// END OF EJS Templates
Wrote test to ensure that number of nargs is calculated correctly.
Wrote test to ensure that number of nargs is calculated correctly.

File last commit:

r20872:19807a85
r20898:afaf3ad0
Show More
shimmodule.py
42 lines | 1.7 KiB | text/x-python | PythonLexer
Thomas Kluyver
Add shim to preserve IPython.qt imports
r20851 """A shim module for deprecated imports
"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Min RK
copy `__spec__` in shim module...
r20872 import sys
Thomas Kluyver
Add shim to preserve IPython.qt imports
r20851 import types
class ShimModule(types.ModuleType):
def __init__(self, *args, **kwargs):
self._mirror = kwargs.pop("mirror")
super(ShimModule, self).__init__(*args, **kwargs)
Min RK
copy `__spec__` in shim module...
r20872 if sys.version_info >= (3,4):
self.__spec__ = __import__(self._mirror).__spec__
Thomas Kluyver
Add shim to preserve IPython.qt imports
r20851
def __getattr__(self, key):
# Use the equivalent of import_item(name), see below
name = "%s.%s" % (self._mirror, key)
Min RK
use getattr in import_item, shim_module...
r20859 # NOTE: the code below was copied *verbatim* from
Thomas Kluyver
Add shim to preserve IPython.qt imports
r20851 # 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
# I couldn't find a way to make the code work as a standard function
# call. But at least since it's an unmodified copy of import_item,
# which is used extensively and has a test suite, we can be reasonably
# confident this is OK. If anyone finds how to call the function, all
# the below could be replaced simply with:
#
# from IPython.utils.importstring import import_item
# return import_item('MIRROR.' + key)
parts = name.rsplit('.', 1)
if len(parts) == 2:
# called with 'foo.bar....'
package, obj = parts
module = __import__(package, fromlist=[obj])
Min RK
use getattr in import_item, shim_module...
r20859 return getattr(module, obj)
Thomas Kluyver
Add shim to preserve IPython.qt imports
r20851 else:
# called with un-dotted string
return __import__(parts[0])