mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
fix the ignoring of __cmp__ method on metaclasses #7491
This commit is contained in:
parent
2a08b42e95
commit
4895af4ef1
3 changed files with 16 additions and 1 deletions
|
@ -1222,6 +1222,15 @@ order (MRO) for bases """
|
||||||
# This used to crash
|
# This used to crash
|
||||||
self.assertRaises(TypeError, MyABC.a.__set__, u, 3)
|
self.assertRaises(TypeError, MyABC.a.__set__, u, 3)
|
||||||
|
|
||||||
|
def test_metaclass_cmp(self):
|
||||||
|
# See bug 7491.
|
||||||
|
class M(type):
|
||||||
|
def __cmp__(self, other):
|
||||||
|
return -1
|
||||||
|
class X(object):
|
||||||
|
__metaclass__ = M
|
||||||
|
self.assertTrue(X < M)
|
||||||
|
|
||||||
def test_dynamics(self):
|
def test_dynamics(self):
|
||||||
# Testing class attribute propagation...
|
# Testing class attribute propagation...
|
||||||
class D(object):
|
class D(object):
|
||||||
|
|
|
@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 2?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #7491: Metaclass's __cmp__ method was ignored.
|
||||||
|
|
||||||
- Issue #7466: segmentation fault when the garbage collector is called
|
- Issue #7466: segmentation fault when the garbage collector is called
|
||||||
in the middle of populating a tuple. Patch by Florent Xicluna.
|
in the middle of populating a tuple. Patch by Florent Xicluna.
|
||||||
|
|
||||||
|
|
|
@ -628,7 +628,11 @@ type_richcompare(PyObject *v, PyObject *w, int op)
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
/* Make sure both arguments are types. */
|
/* Make sure both arguments are types. */
|
||||||
if (!PyType_Check(v) || !PyType_Check(w)) {
|
if (!PyType_Check(v) || !PyType_Check(w) ||
|
||||||
|
/* If there is a __cmp__ method defined, let it be called instead
|
||||||
|
of our dumb function designed merely to warn. See bug
|
||||||
|
#7491. */
|
||||||
|
Py_TYPE(v)->tp_compare || Py_TYPE(w)->tp_compare) {
|
||||||
result = Py_NotImplemented;
|
result = Py_NotImplemented;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue