new.instancemethod as a form of partial()

Alex Martelli aleax at mail.comcast.net
Sun Jan 22 07:24:21 CET 2006


<bonono at gmail.com> wrote:
   ...
> So it seems that instancemethod() don't like "None" as the instance.

"bound methods" and "unbound methods" are instance of the same type,
distinguished by one thing: the im_self of an unbound method is None,
the im_self of a bound method is anything else.

So, when you pass None as the instance, instancemethod likes it just
fine... and returns an "unbound method" as the result, so you haven't
actually achieved your goal (you must still pass the first parameter
explicitly -- all you've "gained" by wrapping a function into an unbound
method is an implicit typecheck on the first argument, and if, as the
class, you're using 'object' as in your example, that's not much use
[even in other cases, it's no great shakes;-)]).


Alex



More information about the Python-list mailing list