classification
Title: metaclass __cmp__ is ignored
Type: Stage:
Components: Interpreter Core Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, exarkun, flox
Priority: normal Keywords:

Created on 2009-12-13 15:58 by exarkun, last changed 2009-12-16 03:37 by benjamin.peterson. This issue is now closed.

Messages (6)
msg96334 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-12-13 15:58
Here's an example of a metaclass with a __cmp__ special:

    exarkun@boson:/tmp$ cat metacmp.py
    class X(type):
        def __cmp__(self, other):
            return -1

    class Y:
        __metaclass__ = X

    print Y < Y
    exarkun@boson:/tmp$ python2.5 metacmp.py
    True
    exarkun@boson:/tmp$ python2.6 metacmp.py
    False
    exarkun@boson:/tmp$

In Python 2.6 and Python 2.7a1, the __cmp__ isn't even invoked, as it
was in Python 2.5.

This breaks the ordering of item types in Axiom.  A brief search reveals
that sympy also ran into the problem, but they may have since worked
around it.
msg96335 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-12-13 16:01
Apparently type has __lt__ and the other rich cmp specials in Python
2.6, but lacked them in Python 2.5.  I suppose these are probably being
given precedence over the overridden __cmp__.
msg96336 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-12-13 16:05
It seems that type was switched to use tp_richcompare in r61529:

Add py3k warnings for object, type, cell and dict comparisons. This
should resolve issue2342 and partly resolve issue2373.
msg96337 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-12-13 16:37
Fixed in r76794.
msg96460 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-15 19:45
Note: test_py3kwarn fails, probably since r76794.
msg96476 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-12-16 03:37
Fixed in r76852.
History
Date User Action Args
2009-12-16 03:37:12benjamin.petersonsetmessages: + msg96476
2009-12-15 19:45:51floxsetnosy: + flox
messages: + msg96460
2009-12-13 16:37:16benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg96337

resolution: fixed
2009-12-13 16:05:11exarkunsetmessages: + msg96336
2009-12-13 16:01:36exarkunsetmessages: + msg96335
2009-12-13 15:58:44exarkuncreate