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
(cherry picked from commit 2aaf98c16ae3070378de523a173e29644037d8bd)
Co-authored-by: INADA Naoki <methane@users.noreply.github.com>
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 8f91bc9..e7202cd 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1961,6 +1961,15 @@
with self.assertRaises(TypeError):
type('A', (B,), {'__slots__': '__weakref__'})
+ def test_namespace_order(self):
+ # bpo-34320: namespace should preserve order
+ od = collections.OrderedDict([('a', 1), ('b', 2)])
+ od.move_to_end('a')
+ expected = list(od.items())
+
+ C = type('C', (), od)
+ self.assertEqual(list(C.__dict__.items())[:2], [('b', 2), ('a', 1)])
+
def load_tests(loader, tests, pattern):
from doctest import DocTestSuite