mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
bpo-34880: Add the LOAD_ASSERTION_ERROR opcode. (GH-15073)
Fix assert statement misbehavior if AssertionError is shadowed.
This commit is contained in:
parent
8371799e30
commit
ce6a070414
14 changed files with 2664 additions and 2627 deletions
|
@ -1285,6 +1285,22 @@ class ExceptionTests(unittest.TestCase):
|
|||
next(i)
|
||||
next(i)
|
||||
|
||||
@unittest.skipUnless(__debug__, "Won't work if __debug__ is False")
|
||||
def test_assert_shadowing(self):
|
||||
# Shadowing AssertionError would cause the assert statement to
|
||||
# misbehave.
|
||||
global AssertionError
|
||||
AssertionError = TypeError
|
||||
try:
|
||||
assert False, 'hello'
|
||||
except BaseException as e:
|
||||
del AssertionError
|
||||
self.assertIsInstance(e, AssertionError)
|
||||
self.assertEqual(str(e), 'hello')
|
||||
else:
|
||||
del AssertionError
|
||||
self.fail('Expected exception')
|
||||
|
||||
|
||||
class ImportErrorTests(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue