Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

pinject failed to assign value to functions with default value #25

Open
tnstar opened this issue Oct 16, 2018 · 0 comments
Open

pinject failed to assign value to functions with default value #25

tnstar opened this issue Oct 16, 2018 · 0 comments

Comments

@tnstar
Copy link

tnstar commented Oct 16, 2018

I can't figure out a way to assign values to class with default init values.
Example as below.
I expect the output to be 'bbb' instead of 'B'.
Am I missing something? please help.

import pinject

class A(object):
    def __init__(self, a, b='B'):
        self.a=a
        self.b=b

class B(object):
    def __init__(self, obja):
        self.obja = obja

    def printit(self):
        print(self.obja.a)
        print(self.obja.b)

class MyBindingSpec(pinject.BindingSpec):
    def configure(self, bind):
        bind('obja',to_class=A)
        bind('a',to_instance='aaa')
        bind('b',to_instance='bbb')

obj_graph = pinject.new_object_graph(binding_specs=[MyBindingSpec()])
objb = obj_graph.provide(B)
objb.printit()
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant