[Python-ideas] Add 'composable' decorator to functools (with @ matrix multiplication)

Yann Kaiser kaiser.yann at gmail.com
Wed May 6 21:50:41 CEST 2015


On Wed, 6 May 2015 at 08:49 Guido van Rossum <guido at python.org> wrote:

> I realize this is still python-ideas, but does this really leave functions
> with multiple arguments completely out of the picture (except as the first
> stage in the pipeline)?
>

To provide some alternative ideas, what I did in
sigtools.wrappers.Combination[1] was to replace the first argument with the
return value of the previous call while always using the same remaining
(positional and keyword) arguments. In code:

    def __call__(self, arg, *args, **kwargs):
        for function in self.functions:
            arg = function(arg, *args, **kwargs)
        return arg

With this you can even use functions that use different parameters, at the
cost of less strictness:

    def func1(arg, *, kw1, **kwargs):
        ...

    def func2(arg, *, kw2, **kwargs):
        ...

That class is more of a demo for sigtools.signatures.merge[2] rather than
something spawned out of a need however.

[1] http://sigtools.readthedocs.org/en/latest/#sigtools.wrappers.Combination
[2] http://sigtools.readthedocs.org/en/latest/#sigtools.signatures.merge
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150506/48a70ac0/attachment-0001.html>


More information about the Python-ideas mailing list