Has comparison of instancemethods changed between python 2.5 and 2.4?
Frank Niessink
frank at niessink.com
Fri Dec 15 11:38:59 EST 2006
Hi,
I'm trying to get an application working with Python 2.5 that works fine
with Python 2.4. This issue occurs both on Windows XP as well as on Mac OSX.
Some context: I use the publisher/subscribe pattern. Observers can
register a callback with a central 'Publisher' like this:
def registerObserver(self, observer, eventType):
''' Register an observer for an event type. The observer is a
callback method that should expect one argument, an instance
of class Event defined above.
The eventType can be anything hashable, typically a string. '''
observerList = self.__observers.setdefault(eventType, [])
if observer not in observerList:
observerList.append(observer)
Now, with Python 2.5 (and not with Python 2.4) I have a callback that is
not being added to the list because, apparently, it compares equal to
some of the callbacks already in the list. However, the instance the two
methods belong to are different, i.e. id(callback) returns different
values for the two methods. Both callbacks are of type <type
'instancemethod'>. Further investigation shows that "observer ==
observerList[1]" is True.
Has instancemethod.__cmp__ changed between python 2.4 and 2.5?
Thanks, Frank
More information about the Python-list
mailing list