summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-09-26 06:38:36 (GMT)
committerGitHub <noreply@github.com>2018-09-26 06:38:36 (GMT)
commitd45a9613402b686f8afd3dd5b6acf8141f14d711 (patch)
treeec99aa32aba5b44f7200e409679dd547cca1b3d6 /Objects/dictobject.c
parentdc335ae77dfc1fb6a500eb1cd0baf23fcda45434 (diff)
downloadcpython-d45a9613402b686f8afd3dd5b6acf8141f14d711.zip
cpython-d45a9613402b686f8afd3dd5b6acf8141f14d711.tar.gz
cpython-d45a9613402b686f8afd3dd5b6acf8141f14d711.tar.bz2
[3.6] bpo-34320: Fix dict(o) didn't copy order of dict subclass (GH-8624) (GH-9583)
When dict subclass overrides order (`__iter__()`, `keys()`, and `items()`), `dict(o)` should use it instead of dict ordering. https://bugs.python.org/issue34320 (cherry picked from commit 2aaf98c16ae3070378de523a173e29644037d8bd) Co-authored-by: INADA Naoki <methane@users.noreply.github.com> https://bugs.python.org/issue34320
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 0768d11..b55e49c 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -237,6 +237,8 @@ static Py_ssize_t lookdict_split(PyDictObject *mp, PyObject *key,
static int dictresize(PyDictObject *mp, Py_ssize_t minused);
+static PyObject* dict_iter(PyDictObject *dict);
+
/*Global counter used to set ma_version_tag field of dictionary.
* It is incremented each time that a dictionary is created and each
* time that a dictionary is modified. */
@@ -2482,7 +2484,7 @@ dict_merge(PyObject *a, PyObject *b, int override)
return -1;
}
mp = (PyDictObject*)a;
- if (PyDict_Check(b)) {
+ if (PyDict_Check(b) && (Py_TYPE(b)->tp_iter == (getiterfunc)dict_iter)) {
other = (PyDictObject*)b;
if (other == mp || other->ma_used == 0)
/* a.update(a) or a.update({}); nothing to do */