diff options
author | MojoVampire <shadowranger+github@gmail.com> | 2020-03-03 18:50:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-03 18:50:17 (GMT) |
commit | 469325c30e147680543b2f5118b83fd95055a499 (patch) | |
tree | c10fd8f26059cb0e6caef9a7c081d324e4146969 /Objects | |
parent | ae75a294352e9b9487f5dc8e88f068e7e6974dc2 (diff) | |
download | cpython-469325c30e147680543b2f5118b83fd95055a499.zip cpython-469325c30e147680543b2f5118b83fd95055a499.tar.gz cpython-469325c30e147680543b2f5118b83fd95055a499.tar.bz2 |
bpo-35712: Make using NotImplemented in a boolean context issue a deprecation warning (GH-13195)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Objects/object.c b/Objects/object.c index 81de3b8..9c74e07 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1673,6 +1673,22 @@ notimplemented_dealloc(PyObject* ignore) Py_FatalError("deallocating NotImplemented"); } +static int +notimplemented_bool(PyObject *v) +{ + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "NotImplemented should not be used in a boolean context", + 1) < 0) + { + return -1; + } + return 1; +} + +static PyNumberMethods notimplemented_as_number = { + .nb_bool = notimplemented_bool, +}; + PyTypeObject _PyNotImplemented_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "NotImplementedType", @@ -1683,8 +1699,8 @@ PyTypeObject _PyNotImplemented_Type = { 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_as_async*/ - NotImplemented_repr, /*tp_repr*/ - 0, /*tp_as_number*/ + NotImplemented_repr, /*tp_repr*/ + ¬implemented_as_number, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ |