Skip to content

Commit 9590ebd

Browse files
committed
Extract _get_callable_bindings into a top-level function
It's gonna be exposed as part of the public API.
1 parent c5c3978 commit 9590ebd

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

injector/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -796,26 +796,15 @@ def call_with_injection(self, callable, self_=None, args=(), kwargs={}):
796796
:return: Value returned by callable.
797797
"""
798798

799-
def _get_callable_bindings(callable):
800-
if not hasattr(callable, '__bindings__'):
801-
return {}
802-
803-
if callable.__bindings__ == 'deferred':
804-
read_and_store_bindings(callable, _infer_injected_bindings(callable))
805-
noninjectables = getattr(callable, '__noninjectables__', set())
806-
return {k: v for k, v in callable.__bindings__.items() if k not in noninjectables}
807-
808-
bindings = _get_callable_bindings(callable)
799+
bindings = get_bindings(callable)
809800
signature = inspect.signature(callable)
810801
full_args = args
811802
if self_ is not None:
812803
full_args = (self_,) + full_args
813804
bound_arguments = signature.bind_partial(*full_args)
814805

815806
needed = dict(
816-
(k, v)
817-
for (k, v) in bindings.items()
818-
if k not in kwargs and k not in bound_arguments.arguments
807+
(k, v) for (k, v) in bindings.items() if k not in kwargs and k not in bound_arguments.arguments
819808
)
820809

821810
dependencies = self.args_to_inject(
@@ -874,6 +863,16 @@ def repr_key(k):
874863
return dependencies
875864

876865

866+
def get_bindings(callable):
867+
if not hasattr(callable, '__bindings__'):
868+
return {}
869+
870+
if callable.__bindings__ == 'deferred':
871+
read_and_store_bindings(callable, _infer_injected_bindings(callable))
872+
noninjectables = getattr(callable, '__noninjectables__', set())
873+
return {k: v for k, v in callable.__bindings__.items() if k not in noninjectables}
874+
875+
877876
class _BindingNotYetAvailable(Exception):
878877
pass
879878

0 commit comments

Comments
 (0)