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

Can build functions be simplified? #31

Open
kmike opened this issue Jan 11, 2024 · 0 comments
Open

Can build functions be simplified? #31

kmike opened this issue Jan 11, 2024 · 0 comments

Comments

@kmike
Copy link
Member

kmike commented Jan 11, 2024

Currently andi docs suggest this as a build function:

def build(plan):
    instances = {}
    for fn_or_cls, kwargs_spec in plan:
        if isinstance(fn_or_cls, CustomBuilder):
            instances[fn_or_cls.result_class_or_fn] = fn_or_cls.factory(**kwargs_spec.kwargs(instances))
        else:
            instances[fn_or_cls] = fn_or_cls(**kwargs_spec.kwargs(instances))
    return instances

It seems it's possible to make it

def build(plan):
    instances = {}
    for builder, kwargs_spec in plan:
        instances[builder.result_class_or_fn] = builder.factory(**kwargs_spec.kwargs(instances))
    return instances

if we wrap everything to builders in the plan.

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

No branches or pull requests

1 participant