From: Guido van Rossum Date: Mon, 24 Sep 2001 18:47:40 +0000 (+0000) Subject: Another comparison patch-up: comparing a type with a dynamic metatype X-Git-Tag: v2.2.1c1~1651 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d45d8f12ea3b4180ed2e1539aa28e14a150b5ba;p=python Another comparison patch-up: comparing a type with a dynamic metatype to one with a static metatype raised an obscure error. --- diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 42e13846a7..fdf2a41dee 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -921,6 +921,13 @@ def dynamics(): verify(L(3)*2 == 6) verify(L(3)*L(2) == 6) + # Test comparison of classes with dynamic metaclasses + class dynamicmetaclass(type): + __dynamic__ = 1 + class someclass: + __metaclass__ = dynamicmetaclass + verify(someclass != object) + def errors(): if verbose: print "Testing errors..." diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 20c149ec6e..027a568dec 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2033,7 +2033,8 @@ wrap_cmpfunc(PyObject *self, PyObject *args, void *wrapped) if (!PyArg_ParseTuple(args, "O", &other)) return NULL; - if (!PyType_IsSubtype(other->ob_type, self->ob_type)) { + if (other->ob_type->tp_compare != func && + !PyType_IsSubtype(other->ob_type, self->ob_type)) { PyErr_Format( PyExc_TypeError, "%s.__cmp__(x,y) requires y to be a '%s', not a '%s'",