From 104cb4a3bacdf9764f9f8670a80da16390231337 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Jan 2017 02:21:47 +0100 Subject: Run Argument Clinic: METH_VARARGS=>METH_FASTCALL Issue #29286. Run Argument Clinic to get the new faster METH_FASTCALL calling convention for functions using "boring" positional arguments. Manually fix _elementtree: _elementtree_XMLParser_doctype() must remain consistent with the clinic code. --- Objects/clinic/dictobject.c.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Objects/clinic/dictobject.c.h') diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index d0cdfc3eda..3f06c0b5da 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -9,23 +9,27 @@ PyDoc_STRVAR(dict_fromkeys__doc__, "Returns a new dict with keys from iterable and values equal to value."); #define DICT_FROMKEYS_METHODDEF \ - {"fromkeys", (PyCFunction)dict_fromkeys, METH_VARARGS|METH_CLASS, dict_fromkeys__doc__}, + {"fromkeys", (PyCFunction)dict_fromkeys, METH_FASTCALL|METH_CLASS, dict_fromkeys__doc__}, static PyObject * dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value); static PyObject * -dict_fromkeys(PyTypeObject *type, PyObject *args) +dict_fromkeys(PyTypeObject *type, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; PyObject *iterable; PyObject *value = Py_None; - if (!PyArg_UnpackTuple(args, "fromkeys", + if (!_PyArg_UnpackStack(args, nargs, "fromkeys", 1, 2, &iterable, &value)) { goto exit; } + + if (!_PyArg_NoStackKeywords("fromkeys", kwnames)) { + goto exit; + } return_value = dict_fromkeys_impl(type, iterable, value); exit: @@ -40,4 +44,4 @@ PyDoc_STRVAR(dict___contains____doc__, #define DICT___CONTAINS___METHODDEF \ {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__}, -/*[clinic end generated code: output=926326109e3d9839 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=69f3d767ed44e8ec input=a9049054013a1b77]*/ -- cgit v1.2.1 From 2b51b5bb59545d275d04fe958f4d347cb2508027 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 19 Jan 2017 12:37:13 +0100 Subject: dict.get() and dict.setdefault() now use AC Issue #29311: dict.get() and dict.setdefault() methods now use Argument Clinic to parse arguments. Their calling convention changes from METH_VARARGS to METH_FASTCALL which avoids the creation of a temporary tuple. The signature of docstrings is also enhanced. For example, get(...) becomes: get(self, key, default=None, /) --- Objects/clinic/dictobject.c.h | 70 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'Objects/clinic/dictobject.c.h') diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index 3f06c0b5da..21c2b0b3d0 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -44,4 +44,72 @@ PyDoc_STRVAR(dict___contains____doc__, #define DICT___CONTAINS___METHODDEF \ {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__}, -/*[clinic end generated code: output=69f3d767ed44e8ec input=a9049054013a1b77]*/ + +PyDoc_STRVAR(dict_get__doc__, +"get($self, key, default=None, /)\n" +"--\n" +"\n" +"D.get(key[, default]) -> D[key] if key in D, else default."); + +#define DICT_GET_METHODDEF \ + {"get", (PyCFunction)dict_get, METH_FASTCALL, dict_get__doc__}, + +static PyObject * +dict_get_impl(PyDictObject *self, PyObject *key, PyObject *failobj); + +static PyObject * +dict_get(PyDictObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + PyObject *key; + PyObject *failobj = Py_None; + + if (!_PyArg_UnpackStack(args, nargs, "get", + 1, 2, + &key, &failobj)) { + goto exit; + } + + if (!_PyArg_NoStackKeywords("get", kwnames)) { + goto exit; + } + return_value = dict_get_impl(self, key, failobj); + +exit: + return return_value; +} + +PyDoc_STRVAR(dict_setdefault__doc__, +"setdefault($self, key, default=None, /)\n" +"--\n" +"\n" +"D.get(key,default), also set D[key]=default if key not in D."); + +#define DICT_SETDEFAULT_METHODDEF \ + {"setdefault", (PyCFunction)dict_setdefault, METH_FASTCALL, dict_setdefault__doc__}, + +static PyObject * +dict_setdefault_impl(PyDictObject *self, PyObject *key, PyObject *defaultobj); + +static PyObject * +dict_setdefault(PyDictObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + PyObject *key; + PyObject *defaultobj = Py_None; + + if (!_PyArg_UnpackStack(args, nargs, "setdefault", + 1, 2, + &key, &defaultobj)) { + goto exit; + } + + if (!_PyArg_NoStackKeywords("setdefault", kwnames)) { + goto exit; + } + return_value = dict_setdefault_impl(self, key, defaultobj); + +exit: + return return_value; +} +/*[clinic end generated code: output=1b0cea84b4b6989e input=a9049054013a1b77]*/ -- cgit v1.2.1 From ca1f7e8b325371854b2c8396cf3e9aae9f31b5e4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 19 Jan 2017 19:00:30 +0200 Subject: Issue #29311: Argument Clinic generates reasonable name for the parameter "default". --- Objects/clinic/dictobject.c.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'Objects/clinic/dictobject.c.h') diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index 21c2b0b3d0..deec4241ea 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -55,25 +55,25 @@ PyDoc_STRVAR(dict_get__doc__, {"get", (PyCFunction)dict_get, METH_FASTCALL, dict_get__doc__}, static PyObject * -dict_get_impl(PyDictObject *self, PyObject *key, PyObject *failobj); +dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value); static PyObject * dict_get(PyDictObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; PyObject *key; - PyObject *failobj = Py_None; + PyObject *default_value = Py_None; if (!_PyArg_UnpackStack(args, nargs, "get", 1, 2, - &key, &failobj)) { + &key, &default_value)) { goto exit; } if (!_PyArg_NoStackKeywords("get", kwnames)) { goto exit; } - return_value = dict_get_impl(self, key, failobj); + return_value = dict_get_impl(self, key, default_value); exit: return return_value; @@ -89,27 +89,28 @@ PyDoc_STRVAR(dict_setdefault__doc__, {"setdefault", (PyCFunction)dict_setdefault, METH_FASTCALL, dict_setdefault__doc__}, static PyObject * -dict_setdefault_impl(PyDictObject *self, PyObject *key, PyObject *defaultobj); +dict_setdefault_impl(PyDictObject *self, PyObject *key, + PyObject *default_value); static PyObject * dict_setdefault(PyDictObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; PyObject *key; - PyObject *defaultobj = Py_None; + PyObject *default_value = Py_None; if (!_PyArg_UnpackStack(args, nargs, "setdefault", 1, 2, - &key, &defaultobj)) { + &key, &default_value)) { goto exit; } if (!_PyArg_NoStackKeywords("setdefault", kwnames)) { goto exit; } - return_value = dict_setdefault_impl(self, key, defaultobj); + return_value = dict_setdefault_impl(self, key, default_value); exit: return return_value; } -/*[clinic end generated code: output=1b0cea84b4b6989e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6e9d917602373072 input=a9049054013a1b77]*/ -- cgit v1.2.1 From 35d2352df15a03d98bb7296a49fd16032b949bb3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 25 Jan 2017 00:30:04 +0200 Subject: Issues #29311, #29289: Fixed and improved docstrings for dict and OrderedDict methods. --- Objects/clinic/dictobject.c.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'Objects/clinic/dictobject.c.h') diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index deec4241ea..97918e82a7 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -6,7 +6,7 @@ PyDoc_STRVAR(dict_fromkeys__doc__, "fromkeys($type, iterable, value=None, /)\n" "--\n" "\n" -"Returns a new dict with keys from iterable and values equal to value."); +"Create a new dictionary with keys from iterable and values set to value."); #define DICT_FROMKEYS_METHODDEF \ {"fromkeys", (PyCFunction)dict_fromkeys, METH_FASTCALL|METH_CLASS, dict_fromkeys__doc__}, @@ -40,7 +40,7 @@ PyDoc_STRVAR(dict___contains____doc__, "__contains__($self, key, /)\n" "--\n" "\n" -"True if D has a key k, else False."); +"True if the dictionary has a specified key, else False."); #define DICT___CONTAINS___METHODDEF \ {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__}, @@ -49,7 +49,7 @@ PyDoc_STRVAR(dict_get__doc__, "get($self, key, default=None, /)\n" "--\n" "\n" -"D.get(key[, default]) -> D[key] if key in D, else default."); +"Return the value for key if key is in the dictionary, else default."); #define DICT_GET_METHODDEF \ {"get", (PyCFunction)dict_get, METH_FASTCALL, dict_get__doc__}, @@ -83,7 +83,9 @@ PyDoc_STRVAR(dict_setdefault__doc__, "setdefault($self, key, default=None, /)\n" "--\n" "\n" -"D.get(key,default), also set D[key]=default if key not in D."); +"Insert key with a value of default if key is not in the dictionary.\n" +"\n" +"Return the value for key if key is in the dictionary, else default."); #define DICT_SETDEFAULT_METHODDEF \ {"setdefault", (PyCFunction)dict_setdefault, METH_FASTCALL, dict_setdefault__doc__}, @@ -113,4 +115,4 @@ dict_setdefault(PyDictObject *self, PyObject **args, Py_ssize_t nargs, PyObject exit: return return_value; } -/*[clinic end generated code: output=6e9d917602373072 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=91aa6a9f3c402b1b input=a9049054013a1b77]*/ -- cgit v1.2.1 From 9bfb9694a65124a8191cdb8ce7992445d1d0f4d2 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 4 Feb 2017 08:05:07 +0200 Subject: Issue #29311: Regenerate Argument Clinic. --- Objects/clinic/dictobject.c.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Objects/clinic/dictobject.c.h') diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index 97918e82a7..fb1e797de1 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -40,7 +40,7 @@ PyDoc_STRVAR(dict___contains____doc__, "__contains__($self, key, /)\n" "--\n" "\n" -"True if the dictionary has a specified key, else False."); +"True if the dictionary has the specified key, else False."); #define DICT___CONTAINS___METHODDEF \ {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__}, @@ -115,4 +115,4 @@ dict_setdefault(PyDictObject *self, PyObject **args, Py_ssize_t nargs, PyObject exit: return return_value; } -/*[clinic end generated code: output=91aa6a9f3c402b1b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4d57df133cf66e53 input=a9049054013a1b77]*/ -- cgit v1.2.1