diff options
author | Inada Naoki <songofacandy@gmail.com> | 2019-04-12 07:11:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-12 07:11:28 (GMT) |
commit | 9e4f2f3a6b8ee995c365e86d976937c141d867f8 (patch) | |
tree | ecb726d5c086b3ad138f7570529480f0b86eed1c /Objects/clinic | |
parent | 3993ccb6820d4239ce3d9e1c5d31f13b86e0000b (diff) | |
download | cpython-9e4f2f3a6b8ee995c365e86d976937c141d867f8.zip cpython-9e4f2f3a6b8ee995c365e86d976937c141d867f8.tar.gz cpython-9e4f2f3a6b8ee995c365e86d976937c141d867f8.tar.bz2 |
bpo-20180: Use argument clinic for dict.pop() and dict.popitem() (GH-12792)
Diffstat (limited to 'Objects/clinic')
-rw-r--r-- | Objects/clinic/dictobject.c.h | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index 713781c..b87244d 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -116,6 +116,63 @@ exit: return return_value; } +PyDoc_STRVAR(dict_pop__doc__, +"pop($self, key, default=None, /)\n" +"--\n" +"\n" +"Remove specified key and return the corresponding value.\n" +"\n" +"If key is not found, default is returned if given, otherwise KeyError is raised"); + +#define DICT_POP_METHODDEF \ + {"pop", (PyCFunction)(void(*)(void))dict_pop, METH_FASTCALL, dict_pop__doc__}, + +static PyObject * +dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value); + +static PyObject * +dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs) +{ + PyObject *return_value = NULL; + PyObject *key; + PyObject *default_value = NULL; + + if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) { + goto exit; + } + key = args[0]; + if (nargs < 2) { + goto skip_optional; + } + default_value = args[1]; +skip_optional: + return_value = dict_pop_impl(self, key, default_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(dict_popitem__doc__, +"popitem($self, /)\n" +"--\n" +"\n" +"Remove and return a (key, value) pair as a 2-tuple.\n" +"\n" +"Pairs are returned in LIFO (last-in, first-out) order.\n" +"Raises KeyError if the dict is empty."); + +#define DICT_POPITEM_METHODDEF \ + {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, dict_popitem__doc__}, + +static PyObject * +dict_popitem_impl(PyDictObject *self); + +static PyObject * +dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored)) +{ + return dict_popitem_impl(self); +} + PyDoc_STRVAR(dict___reversed____doc__, "__reversed__($self, /)\n" "--\n" @@ -133,4 +190,4 @@ dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored)) { return dict___reversed___impl(self); } -/*[clinic end generated code: output=12c21ce3552d9617 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0fd5cafc61a51d3c input=a9049054013a1b77]*/ |