diff --git a/dependency_injector/injections.py b/dependency_injector/injections.py index 90a5f31a..9e282907 100644 --- a/dependency_injector/injections.py +++ b/dependency_injector/injections.py @@ -1,5 +1,6 @@ """Injections module.""" +import sys import six from .utils import is_provider @@ -9,6 +10,13 @@ from .utils import get_injectable_kwargs from .errors import Error +IS_PYPY = '__pypy__' in sys.builtin_module_names +if IS_PYPY or six.PY3: # pragma: no cover + OBJECT_INIT = six.get_unbound_function(object.__init__) +else: # pragma: no cover + OBJECT_INIT = None + + class Injection(object): """Base injection class.""" @@ -68,11 +76,11 @@ def inject(*args, **kwargs): cls = callback try: cls_init = six.get_unbound_function(cls.__init__) - assert cls_init is not object.__init__ + assert cls_init is not OBJECT_INIT except (AttributeError, AssertionError): raise Error( - 'Class {0} has no __init__() '.format(cls.__module__, - cls.__name__) + + 'Class {0}.{1} has no __init__() '.format(cls.__module__, + cls.__name__) + 'method and could not be decorated with @inject decorator') cls.__init__ = decorator(cls_init) return cls