]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 69431 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Sun, 8 Feb 2009 11:05:01 +0000 (11:05 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 8 Feb 2009 11:05:01 +0000 (11:05 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r69431 | mark.dickinson | 2009-02-08 11:02:10 +0000 (Sun, 08 Feb 2009) | 4 lines

  Issue #1717: add a DeprecationWarning in 3.x on type initialization
  for types that implement tp_reserved (formerly tp_compare) but
  not tp_richcompare.
........

Objects/typeobject.c

index ad0ff334cf4ef44d601e36e5786da9562660140c..d03a958a2f2b2c931f67597803b5e695ed947f12 100644 (file)
@@ -3886,6 +3886,21 @@ PyType_Ready(PyTypeObject *type)
                        goto error;
        }
 
+       /* Warn for a type that implements tp_compare (now known as
+          tp_reserved) but not tp_richcompare. */
+       if (type->tp_reserved && !type->tp_richcompare) {
+               int error;
+               char msg[240];
+               PyOS_snprintf(msg, sizeof(msg),
+                             "Type %.100s defines tp_reserved (formerly "
+                             "tp_compare) but not tp_richcompare. "
+                             "Comparisons may not behave as intended.",
+                             type->tp_name);
+               error = PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1);
+               if (error == -1)
+                       goto error;
+       }
+
        /* All done -- set the ready flag */
        assert(type->tp_dict != NULL);
        type->tp_flags =