[Python-Dev] Equality on method objects
rhamph at gmail.com
Mon Mar 10 17:20:14 CET 2008
On Mon, Mar 10, 2008 at 4:26 AM, Armin Rigo <arigo at tunes.org> wrote:
> Hi Phillip,
> 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".
Adam Olsen, aka Rhamphoryncus
More information about the Python-Dev