diff --git a/kwant/_common.py b/kwant/_common.py index eda672a14e515a74e8bf5937a1a2ffb8d2dbc004..4cd0de1a3e6d4b084f3434bbfffef08871d51ded 100644 --- a/kwant/_common.py +++ b/kwant/_common.py @@ -41,30 +41,6 @@ class UserCodeError(Exception): pass -class ExtensionUnavailable: - """Class that replaces unavailable extension modules in the Kwant namespace. - - Some extensions for Kwant (e.g. 'kwant.continuum') require additional - dependencies that are not required for core functionality. When the - additional dependencies are not installed an instance of this class will - be inserted into Kwant's root namespace to simulate the presence of the - extension and inform users that they need to install additional - dependencies. - - See https://mail.python.org/pipermail/python-ideas/2012-May/014969.html - for more details. - """ - - def __init__(self, name, dependencies): - self.name = name - self.dependencies = ', '.join(dependencies) - - def __getattr__(self, _): - msg = ("'{}' is not available because one or more of the following " - "dependencies are not installed: {}") - raise RuntimeError(msg.format(self.name, self.dependencies)) - - def ensure_isinstance(obj, typ, msg=None): if isinstance(obj, typ): return diff --git a/kwant/continuum/__init__.py b/kwant/continuum/__init__.py index 718f50151795830b73df1f9327aa591997d0cbdc..bc2420e9c7998af5cb7f3b33fe72555e778156d4 100644 --- a/kwant/continuum/__init__.py +++ b/kwant/continuum/__init__.py @@ -6,18 +6,15 @@ # the file AUTHORS.rst at the top-level directory of this distribution and at # http://kwant-project.org/authors. -import sys - -from .._common import ExtensionUnavailable - try: from .discretizer import discretize, discretize_symbolic, build_discretized from ._common import sympify, lambdify from ._common import momentum_operators, position_operators -except ImportError: - sys.modules[__name__] = ExtensionUnavailable(__name__, ('sympy',)) +except ImportError as error: + msg = ("'kwant.continuum' is not available because one or more of its " + "dependencies is not installed.") + raise ImportError(msg) from error -del sys, ExtensionUnavailable __all__ = ['discretize', 'discretize_symbolic', 'build_discretized', 'sympify', 'lambdify']