diff options
author | INADA Naoki <methane@users.noreply.github.com> | 2018-09-26 03:59:00 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-09-26 03:59:00 (GMT) |
commit | 2aaf98c16ae3070378de523a173e29644037d8bd (patch) | |
tree | 78b0a34f1d41d23a8b66e607a30fedfd2eb2a352 /Objects | |
parent | d345bb4d9b6e16c681cd8a4e1fff94ecd6b0bb09 (diff) | |
download | cpython-2aaf98c16ae3070378de523a173e29644037d8bd.zip cpython-2aaf98c16ae3070378de523a173e29644037d8bd.tar.gz cpython-2aaf98c16ae3070378de523a173e29644037d8bd.tar.bz2 |
bpo-34320: Fix dict(o) didn't copy order of dict subclass (GH-8624)
When dict subclass overrides order (`__iter__()`, `keys()`, and `items()`), `dict(o)`
should use it instead of dict ordering.
https://bugs.python.org/issue34320
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/dictobject.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 413557d..fec6967 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -235,6 +235,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. */ @@ -2379,7 +2381,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 */ |