Skip to content

Commit d4c6647

Browse files
methaneambv
authored andcommitted
Stop using Argument Clinic for dict_pop (GH-13935)
1 parent 518dc94 commit d4c6647

File tree

2 files changed

+28
-50
lines changed

2 files changed

+28
-50
lines changed

Objects/clinic/dictobject.c.h

Lines changed: 1 addition & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/dictobject.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,23 +2987,37 @@ dict_clear(PyDictObject *mp, PyObject *Py_UNUSED(ignored))
29872987
Py_RETURN_NONE;
29882988
}
29892989

2990-
/*[clinic input]
2991-
dict.pop
2992-
2993-
key: object
2994-
default: object = NULL
2995-
/
2990+
/*
2991+
We don't use Argument Clinic for dict.pop because it doesn't support
2992+
custom signature for now.
2993+
*/
2994+
PyDoc_STRVAR(dict_pop__doc__,
2995+
"D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n\
2996+
If key is not found, d is returned if given, otherwise KeyError is raised");
29962997

2997-
Remove specified key and return the corresponding value.
2998-
2999-
If key is not found, default is returned if given, otherwise KeyError is raised
3000-
[clinic start generated code]*/
2998+
#define DICT_POP_METHODDEF \
2999+
{"pop", (PyCFunction)(void(*)(void))dict_pop, METH_FASTCALL, dict_pop__doc__},
30013000

30023001
static PyObject *
3003-
dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value)
3004-
/*[clinic end generated code: output=3abb47b89f24c21c input=016f6a000e4e633b]*/
3002+
dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
30053003
{
3006-
return _PyDict_Pop((PyObject*)self, key, default_value);
3004+
PyObject *return_value = NULL;
3005+
PyObject *key;
3006+
PyObject *default_value = NULL;
3007+
3008+
if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) {
3009+
goto exit;
3010+
}
3011+
key = args[0];
3012+
if (nargs < 2) {
3013+
goto skip_optional;
3014+
}
3015+
default_value = args[1];
3016+
skip_optional:
3017+
return_value = _PyDict_Pop((PyObject*)self, key, default_value);
3018+
3019+
exit:
3020+
return return_value;
30073021
}
30083022

30093023
/*[clinic input]

0 commit comments

Comments
 (0)