new.instancemethod as a form of partial()

bonono at gmail.com bonono at gmail.com
Sun Jan 22 01:39:28 EST 2006


Alex Martelli wrote:
> <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;-)]).
>
thanks. So in this special case, None is being treated as a "flag"
rather than just an instance(I just read the doc) like any other
instance and the behaviour is intended. Is there any reason why it is
designed this way ?




More information about the Python-list mailing list