]> granicus.if.org Git - python/commitdiff
Another comparison patch-up: comparing a type with a dynamic metatype
authorGuido van Rossum <guido@python.org>
Mon, 24 Sep 2001 18:47:40 +0000 (18:47 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 24 Sep 2001 18:47:40 +0000 (18:47 +0000)
to one with a static metatype raised an obscure error.

Lib/test/test_descr.py
Objects/typeobject.c

index 42e13846a71a0b6fbc931db3ab73ad9380da3896..fdf2a41dee4e1d38f3037d4c15d97755a315bed0 100644 (file)
@@ -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..."
 
index 20c149ec6ee4799e03d684f7221e94521e91155a..027a568dec971f3810659fc3ad474f82b68155ee 100644 (file)
@@ -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'",