Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support constructing objects with partial default parameters #31

Open
jbcpollak opened this issue Feb 24, 2020 · 4 comments
Open

Support constructing objects with partial default parameters #31

jbcpollak opened this issue Feb 24, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@jbcpollak
Copy link
Contributor

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?

@MennoNij
Copy link

MennoNij commented May 20, 2020

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.

@bobthemighty
Copy link
Owner

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.

@bobthemighty bobthemighty added the enhancement New feature or request label Jun 5, 2020
@jbcpollak
Copy link
Contributor Author

Thanks for looking into both issues!

@jbcpollak
Copy link
Contributor Author

Hi @bobthemighty , just wondering if you ever got a chance to look at this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants