[Python-ideas] Make partial a built-in
Steven D'Aprano
steve at pearwood.info
Tue Sep 20 06:31:03 EDT 2016
On Tue, Sep 20, 2016 at 09:56:48AM +0000, אלעזר 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 object's class is a code
smell. It's not necessarily *wrong*, but its a bit... smelly. A bit
suspicious. Something we should think *very* carefully about before
encouraging.
The subtle one is that foo.__call__ may not actually be the method that
is used when you call foo().
py> class X(object):
... def __call__(self):
... return "from X"
...
py> x = X()
py> x.__call__ = lambda: "surprise!"
py> x()
'from X'
py> x.__call__()
'surprise!'
--
Steve
More information about the Python-ideas
mailing list