From: Serhiy Storchaka Date: Thu, 12 Nov 2015 09:34:39 +0000 (+0200) Subject: Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now X-Git-Tag: v3.6.0a1~1077 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12ab296f8212029f43e17f4745abcef89f34ea32;p=python Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now rejects builtin types with not defined __new__. Added tests for non-pickleable types. --- 12ab296f8212029f43e17f4745abcef89f34ea32 diff --cc Lib/test/test_dictviews.py index fcb6814b54,787ef20c47..245f8c858b --- a/Lib/test/test_dictviews.py +++ b/Lib/test/test_dictviews.py @@@ -1,4 -1,5 +1,6 @@@ +import collections + import copy + import pickle import unittest class DictSetTest(unittest.TestCase): @@@ -198,27 -199,22 +200,43 @@@ d[42] = d.values() self.assertRaises(RecursionError, repr, d) + def test_copy(self): + d = {1: 10, "a": "ABC"} + self.assertRaises(TypeError, copy.copy, d.keys()) + self.assertRaises(TypeError, copy.copy, d.values()) + self.assertRaises(TypeError, copy.copy, d.items()) + + def test_pickle(self): + d = {1: 10, "a": "ABC"} + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + self.assertRaises((TypeError, pickle.PicklingError), + pickle.dumps, d.keys(), proto) + self.assertRaises((TypeError, pickle.PicklingError), + pickle.dumps, d.values(), proto) + self.assertRaises((TypeError, pickle.PicklingError), + pickle.dumps, d.items(), proto) + + def test_abc_registry(self): + d = dict(a=1) + + self.assertIsInstance(d.keys(), collections.KeysView) + self.assertIsInstance(d.keys(), collections.MappingView) + self.assertIsInstance(d.keys(), collections.Set) + self.assertIsInstance(d.keys(), collections.Sized) + self.assertIsInstance(d.keys(), collections.Iterable) + self.assertIsInstance(d.keys(), collections.Container) + + self.assertIsInstance(d.values(), collections.ValuesView) + self.assertIsInstance(d.values(), collections.MappingView) + self.assertIsInstance(d.values(), collections.Sized) + + self.assertIsInstance(d.items(), collections.ItemsView) + self.assertIsInstance(d.items(), collections.MappingView) + self.assertIsInstance(d.items(), collections.Set) + self.assertIsInstance(d.items(), collections.Sized) + self.assertIsInstance(d.items(), collections.Iterable) + self.assertIsInstance(d.items(), collections.Container) + if __name__ == "__main__": unittest.main() diff --cc Misc/NEWS index 41a5f8b66e,e1004005be..43f7e70df6 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -10,6 -11,12 +10,9 @@@ Release date: XXXX-XX-X Core and Builtins ----------------- + - Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now + rejects builtin types with not defined __new__. + -- Issue #25555: Fix parser and AST: fill lineno and col_offset of "arg" node - when compiling AST from Python objects. - - Issue #24802: Avoid buffer overreads when int(), float(), compile(), exec() and eval() are passed bytes-like objects. These objects are not necessarily terminated by a null byte, but the functions assumed they were.