-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Background
Yet one more instance of the "from many-to-many to many-to-one-to-many" trick: Normalizing functions.
When you build a framework that is parametrized by functions provided by the user, you'd need to assume, at some level, something about how these functions can be used within the framework. It's a normal thing to do: Impose a user interface -- an API. The more restrictive the API, the cleaner the framework's code can be -- but also the more annoying it can be for the user to fit their case within these imposed constraints.
Therefore the need for "normalizing" tools -- that is, tools that to help the user get from where they are, what they have, to what they need to talk to the frame work. These tools can be used explicitly (the user uses the tools to prepare their specification) or implicitly (offer a friendly and flexible Postel-principled interface that does a lot of this preparation automatically). Where we should be on the implicit-explicit spectrum depends on the context: Anywhere we are in that spectrum, we need these normalizing tools to implement this separate concern.
Function normalization is one (frequent) instance of this. Even more particular: The function's parameter's kinds.
The kind of a parameter can be a great means to tune the interface of a function, but can become an annoyance when you plug the function in a framework that is meant to do something with that function. What if that framework calls the function with keywords, but you had position-only kinds? Or visa versa. What if your framework doesn't know how to deal with variadics?
For example, being able to go from a function that has the (a, *args, b, **kwargs) (a position only, a variadic positional, a position-or-keyword (the only "nice kind"), and a variadic keyword) to a function that can do the same with only the "nice kind" position-or-keyword (a, args: tuple, b, kwargs: dict) can go a long way.
Tasks
A bunch of (kind-) normalizing functions have popped up organically, following the needs of concrete use cases. These need to be:
- reviewed
- merged (i.e. refactored for more reuse)
- tested for pickability
- probably moved to
i2.wrapper - covered with validation to help the user know what's up before a problem happens
- covered more carefully with tests
- better documented
Here are a list of functions to start with (but there's probably more to hunt):
- In i2.signatures:
all_pk_signature(aliased asch_signature_to_all_pk),normalized_func,ch_variadics_to_non_variadic_kind,tuple_the_args(a partial ofch_variadics_to_non_variadic_kind). - In
i2.wrapper:nice_kinds
Things to consider
┆Issue is synchronized with this Asana task by Unito
