mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #1717: add a DeprecationWarning in 3.x on type initialization
for types that implement tp_reserved (formerly tp_compare) but not tp_richcompare.
This commit is contained in:
parent
598c3a8ad1
commit
2a7d45b680
1 changed files with 15 additions and 0 deletions
|
@ -3886,6 +3886,21 @@ PyType_Ready(PyTypeObject *type)
|
||||||
goto error;
|
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 */
|
/* All done -- set the ready flag */
|
||||||
assert(type->tp_dict != NULL);
|
assert(type->tp_dict != NULL);
|
||||||
type->tp_flags =
|
type->tp_flags =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue