Skip to content

Commit 35b5eaa

Browse files
gh-118767: Improve tests and docs for bool(NotImplemented) (#118813)
1 parent 82acc5f commit 35b5eaa

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

Doc/library/constants.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ A small number of constants live in the built-in namespace. They are:
5353
See :exc:`NotImplementedError` for details on when to use it.
5454

5555
.. versionchanged:: 3.9
56-
Evaluating :data:`!NotImplemented` in a boolean context is deprecated. While
57-
it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
58-
It will raise a :exc:`TypeError` in a future version of Python.
56+
Evaluating :data:`!NotImplemented` in a boolean context was deprecated.
5957

6058
.. versionchanged:: 3.14
6159
Evaluating :data:`!NotImplemented` in a boolean context now raises a :exc:`TypeError`.
60+
It previously evaluated to :const:`True` and emitted a :exc:`DeprecationWarning`
61+
since Python 3.9.
6262

6363

6464
.. index:: single: ...; ellipsis literal

Doc/reference/datamodel.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ See
170170
for more details.
171171

172172
.. versionchanged:: 3.9
173-
Evaluating :data:`NotImplemented` in a boolean context is deprecated. While
174-
it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
175-
It will raise a :exc:`TypeError` in a future version of Python.
173+
Evaluating :data:`NotImplemented` in a boolean context was deprecated.
176174

177175
.. versionchanged:: 3.14
178176
Evaluating :data:`NotImplemented` in a boolean context now raises a :exc:`TypeError`.
177+
It previously evaluated to :const:`True` and emitted a :exc:`DeprecationWarning`
178+
since Python 3.9.
179179

180180

181181
Ellipsis

Lib/test/test_builtin.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,15 +2125,17 @@ def test_construct_singletons(self):
21252125
self.assertRaises(TypeError, tp, 1, 2)
21262126
self.assertRaises(TypeError, tp, a=1, b=2)
21272127

2128-
def test_warning_notimplemented(self):
2129-
# Issue #35712: NotImplemented is a sentinel value that should never
2128+
def test_bool_notimplemented(self):
2129+
# GH-79893: NotImplemented is a sentinel value that should never
21302130
# be evaluated in a boolean context (virtually all such use cases
21312131
# are a result of accidental misuse implementing rich comparison
21322132
# operations in terms of one another).
2133-
self.assertRaises(TypeError, bool, NotImplemented)
2134-
with self.assertRaises(TypeError):
2135-
self.assertTrue(NotImplemented)
2136-
with self.assertRaises(TypeError):
2133+
msg = "NotImplemented should not be used in a boolean context"
2134+
self.assertRaisesRegex(TypeError, msg, bool, NotImplemented)
2135+
with self.assertRaisesRegex(TypeError, msg):
2136+
if NotImplemented:
2137+
pass
2138+
with self.assertRaisesRegex(TypeError, msg):
21372139
not NotImplemented
21382140

21392141

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Using :data:`NotImplemented` in a boolean context now raises
2-
:exc:`TypeError`. Contributed by Jelle Zijlstra in :gh:`118767`.
2+
:exc:`TypeError`. Contributed by Jelle Zijlstra.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy