cpython: 489ad68b35c0 (original) (raw)

Mercurial > cpython

changeset 104234:489ad68b35c0

Issue #27358: Optimized merging var-keyword arguments and improved error message when pass a non-mapping as a var-keyword argument. [#27358]

Serhiy Storchaka storchaka@gmail.com
date Sun, 02 Oct 2016 11:07:29 +0300
parents 818e5416ab39(current diff)148172f75d43(diff)
children 6f299f7d6643
files Misc/NEWS Python/ceval.c
diffstat 5 files changed, 127 insertions(+), 56 deletions(-)[+] [-] Include/dictobject.h 6 Lib/test/test_extcall.py 25 Misc/NEWS 3 Objects/dictobject.c 45 Python/ceval.c 104

line wrap: on

line diff

--- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -132,6 +132,12 @@ PyAPI_FUNC(int) PyDict_Merge(PyObject m int override); #ifndef Py_LIMITED_API +/ Like PyDict_Merge, but override can be 0, 1 or 2. If override is 0,

#endif

--- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -259,6 +259,31 @@ not function ... TypeError: h() argument after ** must be a mapping, not function

+

+

+

+

+ >>> dir(**h) Traceback (most recent call last): ...

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -54,6 +54,9 @@ Core and Builtins Library ------- +- Issue #27358: Optimized merging var-keyword arguments and improved error

--- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2380,18 +2380,14 @@ Return: } int -PyDict_Update(PyObject *a, PyObject *b) -{

-} - -int -PyDict_Merge(PyObject *a, PyObject *b, int override) +dict_merge(PyObject *a, PyObject *b, int override) { PyDictObject *mp, *other; Py_ssize_t i, n; PyDictKeyEntry *entry, *ep0;

+ /* We accept for the argument either a concrete dictionary object, * or an abstract "mapping" object. For the former, we can do * things quite efficiently. For the latter, we only require that @@ -2436,8 +2432,14 @@ PyDict_Merge(PyObject *a, PyObject *b, i int err = 0; Py_INCREF(key); Py_INCREF(value);

@@ -2472,7 +2474,13 @@ PyDict_Merge(PyObject *a, PyObject *b, i return -1; for (key = PyIter_Next(iter); key; key = PyIter_Next(iter)) {

@@ -2499,6 +2507,25 @@ PyDict_Merge(PyObject *a, PyObject *b, i return 0; } +int +PyDict_Update(PyObject *a, PyObject *b) +{

+} + +int +PyDict_Merge(PyObject *a, PyObject *b, int override) +{

+} + +int +_PyDict_MergeEx(PyObject *a, PyObject *b, int override) +{

+} + static PyObject * dict_copy(PyDictObject *mp) {

--- a/Python/ceval.c +++ b/Python/ceval.c @@ -2710,9 +2710,32 @@ PyObject * DISPATCH(); }

+

+

+

@@ -2720,55 +2743,42 @@ PyObject * for (i = oparg; i > 0; i--) { PyObject *arg = PEEK(i);

-

-

-