Is this PEP-able? (syntax for functools.partial-like functionality)

Fábio Santos fabiosantosart at gmail.com
Tue Aug 20 04:28:29 EDT 2013


On 20 Aug 2013 07:22, "Steven D'Aprano" <steve at pearwood.info> wrote:
>
> On Tue, 20 Aug 2013 00:49:16 +0100, Fábio Santos wrote:
>
> > I had an idea for a handy syntax which I thought of while designing a
> > language for fun. This would be a syntax for creating, from a function,
> > a function which is just like it but with some parameters pre-filled.
> > The usage is much like functools.partials, and my proposed syntax is
> > like this:
> >
> > def spam(a, b, c):
> >     ...
> >
> > spam_with_defaults = spam{1, 2}
>
>
> Handy it may be, but why is this usage important enough to deserve new
> syntax? The barrier to entry for new syntax is very high. For example,
> Enums are a common, and standard, feature in many programming languages.
> Enums will be introduced to Python in 3.4, but even they don't get
> special syntax.
>
>
>
> --
> Steven

I do realize that syntax in python is practically written in stone, but I
have seen changes come by if they have good reasons. For example,
keyword-only argument syntax was added.

I suggested this because I thought it would be the most practical way to
create partial functions. Lambda is too verbose and kind of ugly, and its
purpose is not to create partials, functools.partial does not allow
argument "insertion" (the star thing) nor unpacking.

Maybe I saw this as common usage but it is really a special case. I see
myself needing this kind of advanced partials _very_ often.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130820/972ddc34/attachment.html>


More information about the Python-list mailing list