it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
It will raise a :exc:`TypeError` in a future version of Python.
+ .. versionchanged:: 3.14
+ Evaluating :data:`!NotImplemented` in a boolean context now raises a :exc:`TypeError`.
+
.. index:: single: ...; ellipsis literal
.. data:: Ellipsis
it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
It will raise a :exc:`TypeError` in a future version of Python.
+.. versionchanged:: 3.14
+ Evaluating :data:`NotImplemented` in a boolean context now raises a :exc:`TypeError`.
+
Ellipsis
--------
Removed
=======
+* Using :data:`NotImplemented` in a boolean context will now raise a :exc:`TypeError`.
+ It had previously raised a :exc:`DeprecationWarning` since Python 3.9. (Contributed
+ by Jelle Zijlstra in :gh:`118767`.)
Porting to Python 3.14
# be evaluated in a boolean context (virtually all such use cases
# are a result of accidental misuse implementing rich comparison
# operations in terms of one another).
- # For the time being, it will continue to evaluate as a true value, but
- # issue a deprecation warning (with the eventual intent to make it
- # a TypeError).
- self.assertWarns(DeprecationWarning, bool, NotImplemented)
- with self.assertWarns(DeprecationWarning):
+ self.assertRaises(TypeError, bool, NotImplemented)
+ with self.assertRaises(TypeError):
self.assertTrue(NotImplemented)
- with self.assertWarns(DeprecationWarning):
- self.assertFalse(not NotImplemented)
+ with self.assertRaises(TypeError):
+ not NotImplemented
class TestBreakpoint(unittest.TestCase):
--- /dev/null
+Using :data:`NotImplemented` in a boolean context now raises
+:exc:`TypeError`. Contributed by Jelle Zijlstra in :gh:`118767`.
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;
+ PyErr_SetString(PyExc_TypeError,
+ "NotImplemented should not be used in a boolean context");
+ return -1;
}
static PyNumberMethods notimplemented_as_number = {