diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-02-08 11:02:10 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-02-08 11:02:10 (GMT) |
commit | 2a7d45b680cb8dde1a57ab149461f721c197647d (patch) | |
tree | 686c3c410370dffceef86524e094466eb96f8468 | |
parent | 598c3a8ad1468bcec8e4b2c4ec8b3069e48289c3 (diff) | |
download | cpython-2a7d45b680cb8dde1a57ab149461f721c197647d.zip cpython-2a7d45b680cb8dde1a57ab149461f721c197647d.tar.gz cpython-2a7d45b680cb8dde1a57ab149461f721c197647d.tar.bz2 |
Issue #1717: add a DeprecationWarning in 3.x on type initialization
for types that implement tp_reserved (formerly tp_compare) but
not tp_richcompare.
-rw-r--r-- | Objects/typeobject.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 05c9ceb..47e425c 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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 = |