diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-07-19 06:18:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-19 06:18:55 (GMT) |
commit | 6bf3237379b17632db52cb39d181e8bac70173f3 (patch) | |
tree | f8e603563cc5cae091f48559c5559b1a3d51339a /Objects/clinic | |
parent | c53b310e5926266ce267c44a168165cacd786d6e (diff) | |
download | cpython-6bf3237379b17632db52cb39d181e8bac70173f3.zip cpython-6bf3237379b17632db52cb39d181e8bac70173f3.tar.gz cpython-6bf3237379b17632db52cb39d181e8bac70173f3.tar.bz2 |
bpo-41333: Convert OrderedDict.pop() to Argument Clinic (GH-21534)
Diffstat (limited to 'Objects/clinic')
-rw-r--r-- | Objects/clinic/dictobject.c.h | 5 | ||||
-rw-r--r-- | Objects/clinic/odictobject.c.h | 45 |
2 files changed, 47 insertions, 3 deletions
diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index 7395e3b..beb3f36 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -122,7 +122,8 @@ PyDoc_STRVAR(dict_pop__doc__, "\n" "D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n" "\n" -"If key is not found, default is returned if given, otherwise KeyError is raised"); +"If the key is not found, return the default if given; otherwise,\n" +"raise a KeyError."); #define DICT_POP_METHODDEF \ {"pop", (PyCFunction)(void(*)(void))dict_pop, METH_FASTCALL, dict_pop__doc__}, @@ -190,4 +191,4 @@ dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored)) { return dict___reversed___impl(self); } -/*[clinic end generated code: output=4d98145508da8fa3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7b77c16e43d6735a input=a9049054013a1b77]*/ diff --git a/Objects/clinic/odictobject.c.h b/Objects/clinic/odictobject.c.h index f43bc14..a3ab9ea 100644 --- a/Objects/clinic/odictobject.c.h +++ b/Objects/clinic/odictobject.c.h @@ -83,6 +83,49 @@ exit: return return_value; } +PyDoc_STRVAR(OrderedDict_pop__doc__, +"pop($self, /, key, default=<unrepresentable>)\n" +"--\n" +"\n" +"od.pop(key[,default]) -> v, remove specified key and return the corresponding value.\n" +"\n" +"If the key is not found, return the default if given; otherwise,\n" +"raise a KeyError."); + +#define ORDEREDDICT_POP_METHODDEF \ + {"pop", (PyCFunction)(void(*)(void))OrderedDict_pop, METH_FASTCALL|METH_KEYWORDS, OrderedDict_pop__doc__}, + +static PyObject * +OrderedDict_pop_impl(PyODictObject *self, PyObject *key, + PyObject *default_value); + +static PyObject * +OrderedDict_pop(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"key", "default", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "pop", 0}; + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; + PyObject *key; + PyObject *default_value = NULL; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { + goto exit; + } + key = args[0]; + if (!noptargs) { + goto skip_optional_pos; + } + default_value = args[1]; +skip_optional_pos: + return_value = OrderedDict_pop_impl(self, key, default_value); + +exit: + return return_value; +} + PyDoc_STRVAR(OrderedDict_popitem__doc__, "popitem($self, /, last=True)\n" "--\n" @@ -168,4 +211,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=8eb1296df9142908 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e0afaad5b4bb47fe input=a9049054013a1b77]*/ |