FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-118767: Make bool(NotImplemented) raise TypeError by JelleZijlstra · Pull Request #118775 · python/cpython · GitHub

/ cpython Public

gh-118767: Make bool(NotImplemented) raise TypeError - #118775

Merged
JelleZijlstra merged 5 commits into
python:mainfrom
JelleZijlstra:boolnotimp
May 8, 2024
Merged

gh-118767: Make bool(NotImplemented) raise TypeError#118775
JelleZijlstra merged 5 commits into
python:mainfrom
JelleZijlstra:boolnotimp

Conversation

JelleZijlstra commented May 8, 2024
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member
>>> bool(NotImplemented)
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    bool(NotImplemented)
    ~~~~^^^^^^^^^^^^^^^^
TypeError: NotImplemented should not be used in a boolean context

📚 Documentation preview 📚: https://cpython-previews--118775.org.readthedocs.build/

JelleZijlstra merged commit 3c079a0 into python:main May 8, 2024
JelleZijlstra deleted the boolnotimp branch May 8, 2024 18:12
Comment thread Doc/library/constants.rst
@@ -57,6 +57,9 @@ A small number of constants live in the built-in namespace. They are:
it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
It will raise a :exc:`TypeError` in a future version of Python.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This can be removed. And maybe the whole text of the note can be reworded.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks, I'll submit another PR addressing your comments.

@@ -174,6 +174,9 @@ for more details.
it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
It will raise a :exc:`TypeError` in a future version of Python.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This can be removed.

Comment thread Lib/test/test_builtin.py
# a TypeError).
self.assertWarns(DeprecationWarning, bool, NotImplemented)
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, bool, NotImplemented)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The test should be renamed.

Comment thread Lib/test/test_builtin.py
self.assertWarns(DeprecationWarning, bool, NotImplemented)
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, bool, NotImplemented)
with self.assertRaises(TypeError):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

TypeError is raised when you just call a function with wrong number of arguments, for example:

with self.assertRaises(TypeError):
    self.assertEqual(NotImplemented)

It is better to not use assertTrue() (which does not work here), but directly test the boolean value:

if NotImplemented:
    pass

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'll also change it to use assertRaisesRegex to test that we're getting the expected TypeError and not some other one.

@@ -0,0 +1,2 @@
Using :data:`NotImplemented` in a boolean context now raises
:exc:`TypeError`. Contributed by Jelle Zijlstra in :gh:`118767`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Isn't the link to the issue already included in the changelog?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks, fixed in the new PR.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL