Skip to content

Commit 36d6f12

Browse files
committed
Add more tests
Update also outdated comment.
1 parent 43b72b0 commit 36d6f12

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

Lib/test/test_capi/test_misc.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -931,11 +931,19 @@ def test_tp_bases_slot_none(self):
931931
def test__pyerr_setkeyerror(self):
932932
# Test _PyErr_SetKeyError()
933933
_pyerr_setkeyerror = _testinternalcapi._pyerr_setkeyerror
934-
with self.assertRaises(KeyError) as cm:
935-
# Test _PyErr_SetKeyError() with an exception set to check
936-
# that the function overrides the current exception
937-
_pyerr_setkeyerror("key")
938-
self.assertEqual(cm.exception.args, ("key",))
934+
for arg in (
935+
"key",
936+
# check that a tuple argument is not unpacked
937+
(1, 2, 3),
938+
KeyError('arg'),
939+
):
940+
with self.subTest(arg=arg):
941+
with self.assertRaises(KeyError) as cm:
942+
# Test calling _PyErr_SetKeyError() with an exception set
943+
# to check that the function overrides the current
944+
# exception.
945+
_pyerr_setkeyerror(arg)
946+
self.assertEqual(cm.exception.args, (arg,))
939947

940948

941949
@requires_limited_api

Python/errors.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,7 @@ PyErr_SetObject(PyObject *exception, PyObject *value)
246246
_PyErr_SetObject(tstate, exception, value);
247247
}
248248

249-
/* Set a key error with the specified argument, wrapping it in a
250-
* tuple automatically so that tuple keys are not unpacked as the
251-
* exception arguments.
249+
/* Set a key error with the specified argument.
252250
*
253251
* If an exception is already set, override the exception. */
254252
void

0 commit comments

Comments
 (0)