]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118767: Improve tests and docs for bool(NotImplemented) (#118813) 118842/head
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Thu, 9 May 2024 13:52:08 +0000 (06:52 -0700)
committerGitHub <noreply@github.com>
Thu, 9 May 2024 13:52:08 +0000 (13:52 +0000)
Doc/library/constants.rst
Doc/reference/datamodel.rst
Lib/test/test_builtin.py
Misc/NEWS.d/next/Core and Builtins/2024-05-08-09-44-15.gh-issue-118767.iFF5F5.rst

index 890517c3eb68dc36f85902690c4d304292476342..6c1063cda6690e9f9128817a9935bad4fc46b9b6 100644 (file)
@@ -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
index fc072b4e75314d647299c273449ccf42d18e3c18..d3e066797f8837a51760f86b3f449cebdcf83dec 100644 (file)
@@ -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
index 120814379dd53ab65e305e2c44dd3078525dc00b..a7631f92e7ea81d87620d3f878168d23fee6a51c 100644 (file)
@@ -2125,15 +2125,17 @@ class BuiltinTest(unittest.TestCase):
             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
 
 
index 76548effd1449fbe94088b15b89efffcfa379fe8..4828f8fbf50cea1d648acf8aab11de04bffd37eb 100644 (file)
@@ -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.