Repository navigation
bpo-36144: Implement defaultdict union. #18729
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 1 commit
eaff8e2
6ba1161
363a913
78c1541
c19d9e7
1662573
a56560e
ec098b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,5 +183,30 @@ def test_pickling(self): | |
| o = pickle.loads(s) | ||
| self.assertEqual(d, o) | ||
|
|
||
| def test_union(self): | ||
| i = defaultdict(int, {1: 1, 2: 2}) | ||
| s = defaultdict(str, {0: "zero", 1: "one"}) | ||
|
|
||
| self.assertIs((i | s).default_factory, int) | ||
| self.assertDictEqual(i | s, {1: "one", 2: 2, 0: "zero"}) | ||
|
Member
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. Is defaultdict not order-preserving, like dict? If it is, could the test check it?
Member
Author
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. You found a flaw in my merge logic! I pushed a fix and added tests for key order. |
||
| self.assertIs((s | i).default_factory, str) | ||
| self.assertDictEqual(s | i, {0: "zero", 1: 1, 2: 2}) | ||
|
|
||
| self.assertIs((i | dict(s)).default_factory, int) | ||
| self.assertDictEqual(i | dict(s), {1: "one", 2: 2, 0: "zero"}) | ||
| self.assertIs((dict(s) | i).default_factory, int) | ||
| self.assertDictEqual(dict(s) | i, {0: "zero", 1: 1, 2: 2}) | ||
|
|
||
| i |= list(s.items()) | ||
| self.assertIs(i.default_factory, int) | ||
| self.assertDictEqual(i, {1: "one", 2: 2, 0: "zero"}) | ||
|
|
||
| with self.assertRaises(TypeError): | ||
| i |= None | ||
| with self.assertRaises(TypeError): | ||
| i | list(s.items()) | ||
| with self.assertRaises(TypeError): | ||
| list(s.items()) | i | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
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 see no tests for ‘|=‘?
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.
defaultdict inherits a perfectly fine
|=fromdict.I can add tests for it here if you'd like, but the tests for
dictalready have the same coverage.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.
D'oh. Maybe add a comment to this effect?