This repository was archived by the owner on Jan 10, 2023. It is now read-only.
Description What is the reasoning for only allowing classes for injection and not allowing all callables?
Most of my providers/factories are simple callables / functions. Adding an unnecessary self parameter does not feel right to me.
An example of what I am trying to do:
def factory_1 (some_value ): return some_value + 2
def some_value (a : int ): return a * 2
data = {"a" : 1 }
class MySpec (pinject .BindingSpec ):
def configure (self , bind ):
for k , v in data .items (): bind (k , to_instance = v )
graph = pinject .new_object_graph (binding_specs = [MySpec ()])
print (graph .provide (factory_1 ))
I would expect the output to be 4
Some things I tried:
setattr (Spec , "provide_some_value" , pinject .provide ("some_value" )(some_value )
For this to work I need to change some_value to
def some_value (self , a : int ): ...
But when I want users to provide their custom providers I don't' want to force them to add this unneeded self.
I hope I could make it understood what I want to achieve. An inspiration are pytest fixtures .
Reactions are currently unavailable
What is the reasoning for only allowing classes for injection and not allowing all callables?
Most of my providers/factories are simple callables / functions. Adding an unnecessary
selfparameter does not feel right to me.An example of what I am trying to do:
I would expect the output to be
4Some things I tried:
For this to work I need to change
some_valuetoBut when I want users to provide their custom providers I don't' want to force them to add this unneeded
self.I hope I could make it understood what I want to achieve. An inspiration are pytest fixtures.