Support constructing objects with partial default parameters
Given code like (this is an untested example):
class A:
pass
class B:
def __init__(a: A, i: int = 0):
pass
container.register(A)
container.register(B)
b = container.resolve(B)
I'm getting a stack trace with this error:
punq.MissingDependencyException: Failed to resolve implementation for <class 'int'>
Is it possible to modify punq to use the inspect library to check for defaults, and leave any unsupplied fields empty?
I'm also running into this problem with attr when a given attribute has a default value, or when using auto_attribs. For instance, taking the above example:
@attr.s(auto_attribs=True)
class B:
i: int
or
@attr.s()
class B:
i: int = attr.ib(default=0)
Will trigger that error.
Hi @jbcpollak . This definitely seems like a thing we should support. I'll take a look over the weekend and seeif we can fix it.
Thanks for looking into both issues!
Hi @bobthemighty , just wondering if you ever got a chance to look at this issue?