On 21 September 2016 at 02:42, Ryan Gonzalez wrote:
> Most often, when I see lambdas used for this, it looks like:
>
> lambda *args, **kw: myfunc(partial_arg, *args, **kw)
Wrapper functions like that are almost always more readable when
written as named functions:
def
אלעזר wrote:
@partial(partial, partial(partial, partial))
def add(a, b, c): return a + b + c
For large numbers of arguments, it's much clearer if you
write it this way:
>>> from functools import partial as badger, partial as mushroom
>>> @badger(badger, badger(badger, badger(badger,
Folks,
There are pros and cons of partial over lambda over classes, and which
you prefer may be at least in part a matter of subjective taste. But
Guido has spoken that he is virulently against making partial a builtin.
It really isn't hard to put "from functools import partial" at the top
This class should be put somewhere. If you need it from inside a method,
you have to choose where to put it. If it is inside the method, it forces
the reader to scan it thoroughly to verify there's no "real" closure there,
and it also makes your methods significantly longer. If it is outside the
On Tue, 20 Sep 2016 15:29:36 +, אלעזר wrote:
> The alternative to partial is writing a closure in the form of a
> function, that needs to be carefully inspected to verify that it is
> indeed just a partial application and not something more complex. It
> has more opportunity for introducing
On Wed, Sep 21, 2016 at 12:04 AM Terry Reedy wrote:
> On 9/20/2016 11:51 AM, Guido van Rossum wrote:
>
> ... (The greater flexibility of lambda, pointed out by David Mertz, is
> another.)
>
>
I just wanted to point out that the greater flexibility of lambda is a very
good
On 9/20/2016 11:51 AM, Guido van Rossum wrote:
We seem to have fundamentally different ideas of what sort of code is
most readable. The alternative to partial is usually a lambda,
Partial and lambda are different in that partial captures variable
values immediately, whereas lambda does not,
On Tue, Sep 20, 2016 at 9:18 PM Stephan Houben wrote:
> I must admit I am a bit partial to partial, you can do fun things like
> this:
>
> >>> from functools import partial
> >>> @partial(partial, partial)
> ... def add(x, y):
> ... return x+y
> ...
> >>> add(3)(4)
> 7
I must admit I am a bit partial to partial, you can do fun things like this:
>>> from functools import partial
>>> @partial(partial, partial)
... def add(x, y):
... return x+y
...
>>> add(3)(4)
7
I suppose that isn't exactly going to convince Guide to put it in builtins,
though.
Stephan
I find myself "partializing" in ways partial() doesn't support more often
than not. E.g.
lambda first, third: myfunc(first, 42, third)
I think it's good to have partial() in functools, but it's two orders of
magnitude less common than things that should be in builtins.
On Sep 20, 2016 9:42 AM,
Le 20 sept. 2016 18:42, "Ryan Gonzalez" a écrit :
> Doing something like:
>
> lambda x, y: myfunc(partial_arg, x, y)
>
> is more error-prone to changes in myfunc's signature.
No, if the signature of the function changes, then the signature of the
partial would also change. The
On Tue, Sep 20, 2016 at 11:51 AM, Guido van Rossum
wrote:
> Also, I once timed it and could not show that partial was faster. This
> surprised me but it was what I measured (in one particular case).
I did similar timings on several occasions in the past and was also
On Tue, Sep 20, 2016 at 8:29 AM, אלעזר wrote:
> Guido, can you please elaborate?
>
> "What's going on" is usually that the same arguments are going to be
> passed over and over again, and the programmer wanted to avoid this
> repetition. The other option is adjusting the
Guido, can you please elaborate?
"What's going on" is usually that the same arguments are going to be passed
over and over again, and the programmer wanted to avoid this repetition.
The other option is adjusting the function to a predefined interface.
The alternative to partial is writing a
I am radically opposed to this proposal. Every time I see a partial
application I wonder endlessly about what's going on.
--Guido (mobile)
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code
On Tue, Sep 20, 2016 at 09:56:48AM +, אלעזר wrote:
> foo.__call__.partial() solves most of the problem I think.
There are two problems with that, one obvious and one subtle.
The obvious one is that __call__ is a dunder method, which means that
accessing it directly from outside of the
Yeah I did say it was a strawman :)
On Tue, Sep 20, 2016 at 11:17 AM Chris Angelico wrote:
> On Tue, Sep 20, 2016 at 6:09 PM, אלעזר wrote:
> > I meant something like making it a "__bind__" (just a strawman
> suggestion)
> > and do the same lookup as foo()
On Tue, Sep 20, 2016 at 10:54 AM Chris Angelico wrote:
> On Tue, Sep 20, 2016 at 5:01 PM, אלעזר wrote:
> > But the foo() finds the function to call, so foo.bind() could be made to
> > find it too.
>
> class Demo:
> def __init__(self):
> self.bind
Hi all,
I would like to add that I don't believe that discoverability is
always better in the `builtins' module.
I personally had the experience of going over itertools, where
I found 'zip_longest', but I couldn't find a 'zip_shortest'.
Only after some googling I found out it was called `zip'
But the foo() finds the function to call, so foo.bind() could be made to
find it too.
בתאריך יום ג׳, 20 בספט' 2016, 08:24, מאת Stefan Behnel :
> אלעזר schrieb am 19.09.2016 um 17:59:
> > If at all, it should be function.bind(). It was discussed and dropped; I
> > don't
אלעזר schrieb am 19.09.2016 um 17:59:
> If at all, it should be function.bind(). It was discussed and dropped; I
> don't remember why, but one problem is that it looks like an in-place
> modification.
IMHO, the main drawback of that solution is that it only works for
functions and not for any
21 matches
Mail list logo