Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Loading