mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
gh-118767: Improve tests and docs for bool(NotImplemented) (#118813)
This commit is contained in:
parent
82acc5f211
commit
35b5eaa176
4 changed files with 15 additions and 13 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue