Revise, refactor and robust(ize) function normalization tools #61
Replies: 2 comments
-
|
@sylvainbonnot says (elsewhere): the jungle of functions changing kinds:
def ch_kinds_to_position_or_keyword(self):
return all_pk_signature(self)used in
|
Beta Was this translation helpful? Give feedback.
-
|
What do you propose as a course of action to minimize how many versions we have? I'd propose:
One problem you might encounter in the above plan is that some functions require wrapping, and others don't. I'd propose therefore to have one general function in Another aspect that's missing in that plan is "what about the methods"? Do we really want to eliminate the methods? Also, we should consider issuing a warning (or raising error) if the use tries to use things like _Note: Ignore anything in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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:
i2.wrapperHere are a list of functions to start with (but there's probably more to hunt):
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).i2.wrapper:nice_kindsThings to consider
┆Issue is synchronized with this Asana task by Unito
Beta Was this translation helpful? Give feedback.
All reactions