-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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: Make bool(NotImplemented) raise TypeError #118775
Conversation
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed. And maybe the whole text of the note can be reworded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed.
# a TypeError). | ||
self.assertWarns(DeprecationWarning, bool, NotImplemented) | ||
with self.assertWarns(DeprecationWarning): | ||
self.assertRaises(TypeError, bool, NotImplemented) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should be renamed.
self.assertWarns(DeprecationWarning, bool, NotImplemented) | ||
with self.assertWarns(DeprecationWarning): | ||
self.assertRaises(TypeError, bool, NotImplemented) | ||
with self.assertRaises(TypeError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the link to the issue already included in the changelog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed in the new PR.
bool(NotImplemented)
into an error #118767📚 Documentation preview 📚: https://cpython-previews--118775.org.readthedocs.build/