diff --git a/injector.py b/injector.py index 3ba3668..4ab34e5 100644 --- a/injector.py +++ b/injector.py @@ -34,7 +34,7 @@ except AttributeError: pass __author__ = 'Alec Thomas ' -__version__ = '0.7.3' +__version__ = '0.7.4' __version_tag__ = '' # To enable get() tracing, getLogger('injector').setLevel(logging.INFO) @@ -611,15 +611,14 @@ class Injector(object): :type kwargs: dict of string -> object :return: Value returned by callable. """ - bindings = getattr(callable, '__bindings__', {}) - needed = dict( - (k, v) for (k, v) in bindings.items() if k not in kwargs) + bindings = getattr(callable, '__bindings__', None) or {} + needed = dict((k, v) for (k, v) in bindings.items() if k not in kwargs) dependencies = self.args_to_inject( function=callable, bindings=needed, - owner_key=self_.__class__ if self_ is not None - else callable.__module__) + owner_key=self_.__class__ if self_ is not None else callable.__module__, + ) dependencies.update(kwargs) @@ -787,8 +786,11 @@ def inject(**bindings): else: inject = f - f.__bindings__ = bindings - inject.__bindings__ = bindings + function_bindings = getattr(f, '__bindings__', None) or {} + merged_bindings = dict(function_bindings, **bindings) + + f.__bindings__ = merged_bindings + inject.__bindings__ = merged_bindings return inject def class_wrapper(cls): diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..1d42e88 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +python_files = *test*.py +addopts = -v --tb=native --doctest-glob=*.md --doctest-modules injector.py injector_test.py README.md +norecursedirs = __pycache__ *venv* .git