mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-118702: Implement vectorcall for BaseException (#118703)
* BaseException_vectorcall() now creates a tuple from 'args' array. * Creation an exception using BaseException_vectorcall() is now a single function call, rather than having to call BaseException_new() and then BaseException_init(). Calling BaseException_init() is inefficient since it overrides the 'args' attribute. * _PyErr_SetKeyError() now uses PyObject_CallOneArg() to create the KeyError instance to use BaseException_vectorcall().
This commit is contained in:
parent
ec9d12be96
commit
aa36f83c16
3 changed files with 68 additions and 4 deletions
|
@ -1817,6 +1817,29 @@ class ExceptionTests(unittest.TestCase):
|
|||
rc, _, err = script_helper.assert_python_ok("-c", code)
|
||||
self.assertIn(b'MemoryError', err)
|
||||
|
||||
def test_keyerror_context(self):
|
||||
# Make sure that _PyErr_SetKeyError() chains exceptions
|
||||
try:
|
||||
err1 = None
|
||||
err2 = None
|
||||
try:
|
||||
d = {}
|
||||
try:
|
||||
raise ValueError("bug")
|
||||
except Exception as exc:
|
||||
err1 = exc
|
||||
d[1]
|
||||
except Exception as exc:
|
||||
err2 = exc
|
||||
|
||||
self.assertIsInstance(err1, ValueError)
|
||||
self.assertIsInstance(err2, KeyError)
|
||||
self.assertEqual(err2.__context__, err1)
|
||||
finally:
|
||||
# Break any potential reference cycle
|
||||
exc1 = None
|
||||
exc2 = None
|
||||
|
||||
|
||||
class NameErrorTests(unittest.TestCase):
|
||||
def test_name_error_has_name(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue