-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-34320: Fix dict(o) didn't copy order of dict subclass #8624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
253f5db
e0bf46c
26ef93f
5b6502d
ee8696d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -650,6 +650,41 @@ def test_free_after_iterating(self): | |
support.check_free_after_iterating(self, lambda d: iter(d.values()), self.OrderedDict) | ||
support.check_free_after_iterating(self, lambda d: iter(d.items()), self.OrderedDict) | ||
|
||
# TODO: This test is relating to PEP 468. | ||
# Move this test to somewhere more appropriate. | ||
def test_kwargs_order(self): | ||
# bpo-34320 | ||
od = self.OrderedDict([('a', 1), ('b', 2)]) | ||
od.move_to_end('a') | ||
expected = list(od.items()) | ||
|
||
def fn(**kw): | ||
return kw | ||
|
||
res = fn(**od) | ||
self.assertIsInstance(res, dict) | ||
self.assertEqual(list(res.items()), expected) | ||
|
||
# TODO: This test is relating to PEP 520. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is not specific to PEP 520, which only relates directly to the class definition namespace. So you should drop this comment. |
||
# Move this test to somewhere more appropriate. | ||
def test_type_namespace_order(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should be next to other tests of the |
||
# bpo-34320 | ||
od = self.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 test_dict_copy_order(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should be in |
||
# bpo-34320 | ||
od = self.OrderedDict([('a', 1), ('b', 2)]) | ||
od.move_to_end('a') | ||
expected = list(od.items()) | ||
|
||
copy = dict(od) | ||
self.assertEqual(list(copy.items()), expected) | ||
|
||
|
||
class PurePythonOrderedDictTests(OrderedDictTests, unittest.TestCase): | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix ``dict(od)`` didn't copy iteration order of OrderedDict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is about
kwargs
ordering rather thanOrderedDict
, so I'd expect it to be next to other tests forkwargs
, not here intest_ordered_dict.py
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but problem is I can't find
other tests for kwargs
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added new test class for this, in test_call.py