[Python-Dev] Equality on method objects
Phillip J. Eby
pje at telecommunity.com
Mon Mar 10 15:55:50 CET 2008
At 12:26 PM 3/10/2008 +0100, Armin Rigo wrote:
>On Sun, Mar 09, 2008 at 07:05:12PM -0400, Phillip J. Eby wrote:
> > I did not, however, need the equality of bound methods to be based on
> > object value equality, just value identity.
> > ...at least until recently, anyway. I do have one library that wants
> > to have equality-based comparison of im_self. What I ended up doing
> > is writing code that tests what the current Python interpreter is
> > doing, and if necessary implements a special method type, just for
> > purposes of working around the absence of im_self equality
> > testing. However, it's a pretty specialized case (...)
>I found myself in exactly the same case: a pretty specialized example
>where I wanted bound methods to use im_self equality rather than
>identity, solved by writing my own bound-method-like object. But that's
>not really hard to do, and the general tendency (which matches my own
>opinion too) seems to be that using im_self identity is less surprizing.
>In general, "x.append" is interchangeable with "x.append" even if
>"x.append is not x.append", so let's go for the least surprizing
>behavior: "m1.im_self is m2.im_self and m1.im_func==m2.im_func".
Nope; that's exactly what I proposed at the end of the email quoted above.
More information about the Python-Dev