Skip to content

Add FuncFactory control over signature of factories. #39

@thorwhalen

Description

@thorwhalen

Take this:

def doit(obj, a, b=2):
    """do something amazing"""

When we want to make a factory based on this function, we can do:

from i2 import FuncFactory

factory = FuncFactory(doit)

All well and good, and though one of the advantages of FuncFactory is that it gives the user a useful signature so they know what parameters they can use to control what (partial) object the factory makes.

from is import Sig

str(Sig(factory))
# `(obj, a, b=2)`

This is the right, full, signature. It shows, for example, that you can tell your factory that you want a parametrize doit function with obj=something, but what if you actually don't want the user to parametrize obj (for example, because it makes no sense, given what doit actually does? In this case it would be better to be able to do something like:

factory = FuncFactory(doit, exclude=0)  # or exclude=[0] or exclude='obj' or exclude=['obj']
# or/and
factory = FuncFactory(doit, include='a b')  # or include=[1, 2] or include=['a', 'b']

to result in

str(Sig(factory))
# `(a, b=2)`

Note: This functionality can of course be externalized, by given the user the ability (e.g. through a i2.wrapper tool) to take care of this after the original FuncFactory was made. Is the current proposal's convenience worth the extra (minor) complexity?

Note: Should make sure to test if a simple signature change would be enough, or if we need some i2.wrapper wrap and argument rewiring. Also, note that the only-signature method would still allow the user to access underlying arguments (though they're not in the signature).

┆Issue is synchronized with this Asana task by Unito

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions