Skip to content

Commit

Permalink
Fix regression
Browse files Browse the repository at this point in the history
Injecting into methods of false-ish objects would fail
  • Loading branch information
jstasiak committed Jul 10, 2013
1 parent f64cc36 commit 4bb75cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,15 @@ def call_with_injection(self, callable, self_, args=(), kwargs={}):
dependencies = self.args_to_inject(
function=callable,
bindings=needed,
owner_key=self_.__class__ if self_ else callable.__module__)
owner_key=self_.__class__ if self_ is not None
else callable.__module__)

dependencies.update(kwargs)

try:
return callable(*((self_,) if self_ else ()) + tuple(args), **dependencies)
return callable(
*((self_,) if self_ is not None else ()) + tuple(args),
**dependencies)
except TypeError as e:
reraise(e, CallError(self_, callable, args, dependencies, e))

Expand Down
12 changes: 12 additions & 0 deletions injector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,3 +982,15 @@ def singleton_provides():

assert provides_singleton.__binding__.scope == SingletonScope
assert singleton_provides.__binding__.scope == SingletonScope


def test_injecting_into_method_of_object_that_is_falseish_works():
# regression test

class X(dict):
@inject(s=str)
def __init__(self, s):
pass

injector = Injector()
injector.get(X)

0 comments on commit 4bb75cf

Please sign in to comment.