]> granicus.if.org Git - python/commitdiff
Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 12 Nov 2015 09:34:39 +0000 (11:34 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 12 Nov 2015 09:34:39 +0000 (11:34 +0200)
rejects builtin types with not defined __new__.
Added tests for non-pickleable types.

1  2 
Lib/test/test_dictviews.py
Misc/NEWS
Objects/typeobject.c

index fcb6814b54206d6a78e0c8a5a9379ba1039940fb,787ef20c47df2d58f3076b2443397c56bc0aacbc..245f8c858b69bcfe2c1c47a02a7dc83592b07981
@@@ -1,4 -1,5 +1,6 @@@
 +import collections
+ import copy
+ import pickle
  import unittest
  
  class DictSetTest(unittest.TestCase):
          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 41a5f8b66ee786b866dddf77d35cc7940340683e,e1004005beaf4e4cd52359d9aa905fd19b32702a..43f7e70df646f76e2e0b6a08c0ee5460962d0494
+++ b/Misc/NEWS
@@@ -10,6 -11,12 +10,9 @@@ Release date: XXXX-XX-X
  Core and Builtins
  -----------------
  
 -- Issue #25555: Fix parser and AST: fill lineno and col_offset of "arg" node
 -  when compiling AST from Python objects.
 -
+ - Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
+   rejects builtin types with not defined __new__.
  - 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.
Simple merge