This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: __cmp__ present in type but not instance??
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, lpd
Priority: normal Keywords:

Created on 2007-06-03 22:04 by lpd, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg32202 - (view) Author: L. Peter Deutsch (lpd) Date: 2007-06-03 22:04
hasattr(list, '__cmp__') is True, but hasattr([], '__cmp__') is False.  Doesn't the Python story about instances and classes forbid this!?
msg32203 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-06-03 22:51
Do a dir() on list and on [] and you will notice that __cmp__ doesn't show up.  The __cmp__ you are seeing is the type instance method of list as received from being a subclass of 'type'.  It's more obvious if you print out list.__cmp__ and type.__cmp__.

So it does make sense when viewed from the point-of-view of metaclasses; list is an instance of type and you are seeing a metaclass instance method on list.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 45032
2007-06-03 22:04:35lpdcreate