[Python-ideas] A suggestion for Python 3 vs Python 2
אלעזר
elazarg at gmail.com
Thu Nov 14 21:00:07 CET 2013
2013/11/14 Bruce Leban <bruce at leapyear.org>:
> 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)
>
You get this automatically for partial-as-method:
partial_sub = sub.partial
sub5 = partial_sub(_, 5)
It will not happen in accident (or at least it is very unlikely) so
there'll be no need for an exception; when it does happen in accident,
the behavior is easily understood.
You also get cleaner separation of the parameters' roles - after all,
x.foo *is* partial(<things>).
Elazar
More information about the Python-ideas
mailing list