Skip to content

Resolving with * #207

@belegnar

Description

@belegnar

Consider the following snippet

import punq


class I:
    pass


class E:
    def __init__(self, host, user=None):
        self.host = host
        self.user = user


class A(I):
    def __init__(self, host, user=None):
        self.host = host
        self.user = user


class B(E, I):
    def __init__(self, host, user=None):
        super().__init__(host, user=user)


if __name__ == '__main__':
    c = punq.Container()
    c.register(I, factory=A)
    c.register(I, factory=B)

    for impl in c.resolve_all(I, host="host", user="user"):
        print(impl.__class__, impl.host, impl.user)

In this implementation it prints

<class '__main__.A'> host user
<class '__main__.B'> host user

But if __init__s are replaced with (add *)

    def __init__(self, host, *, user=None):

the user is lost

<class '__main__.A'> host None
<class '__main__.B'> host None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions