From 72d3cc94cd8cae1925e7a14f297b06ac6184f916 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 7 Mar 2024 11:21:08 +0200 Subject: gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438) --- Python/bytecodes.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Python/bytecodes.c') diff --git a/Python/bytecodes.c b/Python/bytecodes.c index bf0583d9c69..3276a4a9644 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1307,14 +1307,14 @@ dummy_func( inst(DELETE_GLOBAL, (--)) { PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); - int err; - err = PyDict_DelItem(GLOBALS(), name); + int err = PyDict_Pop(GLOBALS(), name, NULL); // Can't use ERROR_IF here. - if (err != 0) { - if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) { - _PyEval_FormatExcCheckArg(tstate, PyExc_NameError, - NAME_ERROR_MSG, name); - } + if (err < 0) { + GOTO_ERROR(error); + } + if (err == 0) { + _PyEval_FormatExcCheckArg(tstate, PyExc_NameError, + NAME_ERROR_MSG, name); GOTO_ERROR(error); } } -- cgit v1.2.3