[ python-Bugs-1400227 ] 'is' does not work on methods

SourceForge.net noreply at sourceforge.net
Mon Jan 9 11:04:20 CET 2006


Bugs item #1400227, was opened at 2006-01-09 05:04
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1400227&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Collin Winter (collinwinter)
Assigned to: Nobody/Anonymous (nobody)
Summary: 'is' does not work on methods

Initial Comment:
As of Python 2.4.2 (gcc 3.3.6, linux 2.6.13), the 'is'
comparison operator does not work on instancemethods or
classmethods (though it does work on staticmethods).
For example:

"""
>>> class A(object):
...   def foo(self): pass
...
>>> id(A.foo) == id(A.foo)
True
>>> A.foo is A.foo
False
>>>
>>> a = A()
>>> id(a.foo) == id(a.foo)
True
>>> a.foo is a.foo
False
"""

This example is applicable to old-style classes and
new-style classes, though things get more complicated
in the case of built-in types:

"""
>>> d = dict()
>>> id(d.update) == id(d.update)
True
>>> d.update is d.update
False
>>>
>>> id(dict.update) == id(dict.update)
True
>>> dict.update is dict.update
True
"""

However, using the classmethod 'fromkeys':

"""
>>> d = dict()
>>> id(d.fromkeys) == id(d.fromkeys)
True
>>> d.fromkeys is d.fromkeys
False
>>>
>>> id(dict.fromkeys) == id(dict.fromkeys)
True
>>> dict.fromkeys is dict.fromkeys
False
"""

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1400227&group_id=5470


More information about the Python-bugs-list mailing list