diff options
author | Brandt Bucher <brandtbucher@gmail.com> | 2020-03-07 19:03:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-07 19:03:09 (GMT) |
commit | 4663f66f3554dd8e2ec130e40f6abb3c6a514775 (patch) | |
tree | 479bda23ce4895419248e76431066a81d9088c94 /Lib | |
parent | 8f130536926a30237b5297780d61ef4232e88577 (diff) | |
download | cpython-4663f66f3554dd8e2ec130e40f6abb3c6a514775.zip cpython-4663f66f3554dd8e2ec130e40f6abb3c6a514775.tar.gz cpython-4663f66f3554dd8e2ec130e40f6abb3c6a514775.tar.bz2 |
bpo-36144: Update MappingProxyType with PEP 584's operators (#18814)
We make `|=` raise TypeError, since it would be surprising if `C.__dict__ |= {'x': 0}` silently did nothing, while `C.__dict__.update({'x': 0})` is an error.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_types.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 7b45b7a..544c91b 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -622,8 +622,11 @@ class MappingProxyTests(unittest.TestCase): self.assertEqual(attrs, { '__contains__', '__getitem__', + '__ior__', '__iter__', '__len__', + '__or__', + '__ror__', 'copy', 'get', 'items', @@ -774,6 +777,22 @@ class MappingProxyTests(unittest.TestCase): self.assertEqual(view['key1'], 70) self.assertEqual(copy['key1'], 27) + def test_union(self): + mapping = {'a': 0, 'b': 1, 'c': 2} + view = self.mappingproxy(mapping) + with self.assertRaises(TypeError): + view | [('r', 2), ('d', 2)] + with self.assertRaises(TypeError): + [('r', 2), ('d', 2)] | view + with self.assertRaises(TypeError): + view |= [('r', 2), ('d', 2)] + other = {'c': 3, 'p': 0} + self.assertDictEqual(view | other, {'a': 0, 'b': 1, 'c': 3, 'p': 0}) + self.assertDictEqual(other | view, {'c': 2, 'p': 0, 'a': 0, 'b': 1}) + self.assertEqual(view, {'a': 0, 'b': 1, 'c': 2}) + self.assertDictEqual(mapping, {'a': 0, 'b': 1, 'c': 2}) + self.assertDictEqual(other, {'c': 3, 'p': 0}) + class ClassCreationTests(unittest.TestCase): |