[Python-ideas] A suggestion for Python 3 vs Python 2

Bruce Leban bruce at leapyear.org
Thu Nov 14 19:26:16 CET 2013


On Thu, Nov 14, 2013 at 9:58 AM, Andrew Barnert <abarnert at yahoo.com> wrote:

> > sub5 = partial(sub, ..., 5)
> >
> > (At the expense of giving up the abitily to pass ellipsis to partial
> functions).
>
> I don't know why, but to me that strongly implies that I'm binding
> argument -1 (after 0 or more arguments, or maybe 1 or more), rather than
> argument 2 (after exactly 1).
>
> But that's not necessarily a bad thing. But if other people expect it to
> bind 2, they'll be surprised when they try it on a 3-argument (or
> variable-argument) function.
>
> (And yes, I realize that mixing 1-based arg counting with python negative
> indices is potentially confusing. I don't think it's confusing in this
> particular case, but in, say, documentation for a stdlib function it could
> be.)0
>

How about:

from functools import partial, __

sub5 = partial(sub, __, 5)
xyz = partial(x, __, y, __, z)


(Not quote sure what number of _ would work.) Then you could use ... to do
the -1 argument binding:

xyz = partial(x, __, y, ..., z)


Incidentally, since partial(x) doesn't do anything useful (why does it not
raise an exception?) would the following ever be reasonable to support?

sub5 = partial(sub)(__, 5)


The advantage is that the signature of the partial function stands alone
making it easier to read. That is,

def new_partial(func, *args, **kwargs):
    if not args and not kwargs:
        return partial(partial, func)
    return partial(func, *args, **kwargs)


Probably the status quo wins.

--- Bruce
I'm hiring: http://www.cadencemd.com/info/jobs
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131114/5b60688e/attachment-0001.html>


More information about the Python-ideas mailing list