@@ -863,14 +863,43 @@ def repr_key(k):
863
863
return dependencies
864
864
865
865
866
- def get_bindings (callable ):
866
+ def get_bindings (callable : Callable ) -> Dict [str , type ]:
867
+ """Get bindings of injectable parameters from a callable.
868
+
869
+ If the callable is not decorated with :func:`inject` an empty dictionary will
870
+ be returned. Otherwise the returned dictionary will contain a mapping
871
+ between parameter names and their types with the exception of parameters
872
+ excluded from dependency injection with :func:`noninjectable`. For example::
873
+
874
+ >>> def function1(a: int) -> None:
875
+ ... pass
876
+ ...
877
+ >>> get_bindings(function1)
878
+ {}
879
+ >>> @inject
880
+ ... def function2(a: int) -> None:
881
+ ... pass
882
+ ...
883
+ >>> get_bindings(function2)
884
+ {'a': int}
885
+ >>> @inject
886
+ ... @noninjectable('b')
887
+ ... def function3(a: int, b: str) -> None:
888
+ ... pass
889
+ ...
890
+ >>> get_bindings(function3)
891
+ {'a': int}
892
+
893
+ This function is used internally so by calling it you can learn what exactly
894
+ Injector is going to try to provide to a callable.
895
+ """
867
896
if not hasattr (callable , '__bindings__' ):
868
897
return {}
869
898
870
- if callable .__bindings__ == 'deferred' :
899
+ if cast ( Any , callable ) .__bindings__ == 'deferred' :
871
900
read_and_store_bindings (callable , _infer_injected_bindings (callable ))
872
901
noninjectables = getattr (callable , '__noninjectables__' , set ())
873
- return {k : v for k , v in callable .__bindings__ .items () if k not in noninjectables }
902
+ return {k : v for k , v in cast ( Any , callable ) .__bindings__ .items () if k not in noninjectables }
874
903
875
904
876
905
class _BindingNotYetAvailable (Exception ):
0 commit comments