https://github.com/python/cpython/commit/35b5eaa176a5bae8a0cacb9c9f40ec948ecc4325
commit: 35b5eaa176a5bae8a0cacb9c9f40ec948ecc4325
branch: main
author: Jelle Zijlstra <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2024-05-09T13:52:08Z
summary:

gh-118767: Improve tests and docs for bool(NotImplemented) (#118813)

files:
M Doc/library/constants.rst
M Doc/reference/datamodel.rst
M Lib/test/test_builtin.py
M Misc/NEWS.d/next/Core and 
Builtins/2024-05-08-09-44-15.gh-issue-118767.iFF5F5.rst

diff --git a/Doc/library/constants.rst b/Doc/library/constants.rst
index 890517c3eb68dc..6c1063cda6690e 100644
--- a/Doc/library/constants.rst
+++ b/Doc/library/constants.rst
@@ -53,12 +53,12 @@ A small number of constants live in the built-in namespace. 
 They are:
       See :exc:`NotImplementedError` for details on when to use it.
 
    .. versionchanged:: 3.9
-      Evaluating :data:`!NotImplemented` in a boolean context is deprecated. 
While
-      it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
-      It will raise a :exc:`TypeError` in a future version of Python.
+      Evaluating :data:`!NotImplemented` in a boolean context was deprecated.
 
    .. versionchanged:: 3.14
       Evaluating :data:`!NotImplemented` in a boolean context now raises a 
:exc:`TypeError`.
+      It previously evaluated to :const:`True` and emitted a 
:exc:`DeprecationWarning`
+      since Python 3.9.
 
 
 .. index:: single: ...; ellipsis literal
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index fc072b4e75314d..d3e066797f8837 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -170,12 +170,12 @@ See
 for more details.
 
 .. versionchanged:: 3.9
-   Evaluating :data:`NotImplemented` in a boolean context is deprecated. While
-   it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
-   It will raise a :exc:`TypeError` in a future version of Python.
+   Evaluating :data:`NotImplemented` in a boolean context was deprecated.
 
 .. versionchanged:: 3.14
    Evaluating :data:`NotImplemented` in a boolean context now raises a 
:exc:`TypeError`.
+   It previously evaluated to :const:`True` and emitted a 
:exc:`DeprecationWarning`
+   since Python 3.9.
 
 
 Ellipsis
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 120814379dd53a..a7631f92e7ea81 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -2125,15 +2125,17 @@ def test_construct_singletons(self):
             self.assertRaises(TypeError, tp, 1, 2)
             self.assertRaises(TypeError, tp, a=1, b=2)
 
-    def test_warning_notimplemented(self):
-        # Issue #35712: NotImplemented is a sentinel value that should never
+    def test_bool_notimplemented(self):
+        # GH-79893: NotImplemented is a sentinel value that should never
         # 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).
-        self.assertRaises(TypeError, bool, NotImplemented)
-        with self.assertRaises(TypeError):
-            self.assertTrue(NotImplemented)
-        with self.assertRaises(TypeError):
+        msg = "NotImplemented should not be used in a boolean context"
+        self.assertRaisesRegex(TypeError, msg, bool, NotImplemented)
+        with self.assertRaisesRegex(TypeError, msg):
+            if NotImplemented:
+                pass
+        with self.assertRaisesRegex(TypeError, msg):
             not NotImplemented
 
 
diff --git a/Misc/NEWS.d/next/Core and 
Builtins/2024-05-08-09-44-15.gh-issue-118767.iFF5F5.rst b/Misc/NEWS.d/next/Core 
and Builtins/2024-05-08-09-44-15.gh-issue-118767.iFF5F5.rst
index 76548effd1449f..4828f8fbf50cea 100644
--- a/Misc/NEWS.d/next/Core and 
Builtins/2024-05-08-09-44-15.gh-issue-118767.iFF5F5.rst 
+++ b/Misc/NEWS.d/next/Core and 
Builtins/2024-05-08-09-44-15.gh-issue-118767.iFF5F5.rst 
@@ -1,2 +1,2 @@
 Using :data:`NotImplemented` in a boolean context now raises
-:exc:`TypeError`. Contributed by Jelle Zijlstra in :gh:`118767`.
+:exc:`TypeError`. Contributed by Jelle Zijlstra.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to