cpython: 4c05e7c195ac (original) (raw)
Mercurial > cpython
changeset 99075:4c05e7c195ac 3.5
Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now rejects builtin types with not defined __new__. Added tests for non-pickleable types. [#22995]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Thu, 12 Nov 2015 11:31:51 +0200 |
parents | d1737db0f1b2(current diff)c8841db9433d(diff) |
children | a2f574896f49 2c9b5c5b54ae |
files | Lib/test/test_coroutines.py Lib/test/test_dictviews.py Lib/test/test_generators.py Lib/test/test_xml_etree.py Lib/test/test_zlib.py Misc/NEWS Objects/typeobject.c |
diffstat | 7 files changed, 99 insertions(+), 0 deletions(-)[+] [-] Lib/test/test_coroutines.py 30 Lib/test/test_dictviews.py 18 Lib/test/test_generators.py 17 Lib/test/test_xml_etree.py 14 Lib/test/test_zlib.py 11 Misc/NEWS 3 Objects/typeobject.c 6 |
line wrap: on
line diff
--- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -1,5 +1,7 @@ import contextlib +import copy import inspect +import pickle import sys import types import unittest @@ -1318,6 +1320,34 @@ class CoroutineTest(unittest.TestCase): run_async(foo()) self.assertEqual(CNT, 0)
- def test_copy(self):
async def func(): pass[](#l1.16)
coro = func()[](#l1.17)
with self.assertRaises(TypeError):[](#l1.18)
copy.copy(coro)[](#l1.19)
aw = coro.__await__()[](#l1.21)
try:[](#l1.22)
with self.assertRaises(TypeError):[](#l1.23)
copy.copy(aw)[](#l1.24)
finally:[](#l1.25)
aw.close()[](#l1.26)
- def test_pickle(self):
async def func(): pass[](#l1.29)
coro = func()[](#l1.30)
for proto in range(pickle.HIGHEST_PROTOCOL + 1):[](#l1.31)
with self.assertRaises((TypeError, pickle.PicklingError)):[](#l1.32)
pickle.dumps(coro, proto)[](#l1.33)
aw = coro.__await__()[](#l1.35)
try:[](#l1.36)
for proto in range(pickle.HIGHEST_PROTOCOL + 1):[](#l1.37)
with self.assertRaises((TypeError, pickle.PicklingError)):[](#l1.38)
pickle.dumps(aw, proto)[](#l1.39)
finally:[](#l1.40)
aw.close()[](#l1.41)
+ class CoroAsyncIOCompatTest(unittest.TestCase):
--- a/Lib/test/test_dictviews.py +++ b/Lib/test/test_dictviews.py @@ -1,3 +1,5 @@ +import copy +import pickle import unittest class DictSetTest(unittest.TestCase): @@ -197,6 +199,22 @@ class DictSetTest(unittest.TestCase): d[42] = d.values() self.assertRaises(RecursionError, repr, d)
- def test_copy(self):
d = {1: 10, "a": "ABC"}[](#l2.14)
self.assertRaises(TypeError, copy.copy, d.keys())[](#l2.15)
self.assertRaises(TypeError, copy.copy, d.values())[](#l2.16)
self.assertRaises(TypeError, copy.copy, d.items())[](#l2.17)
- def test_pickle(self):
d = {1: 10, "a": "ABC"}[](#l2.20)
for proto in range(pickle.HIGHEST_PROTOCOL + 1):[](#l2.21)
self.assertRaises((TypeError, pickle.PicklingError),[](#l2.22)
pickle.dumps, d.keys(), proto)[](#l2.23)
self.assertRaises((TypeError, pickle.PicklingError),[](#l2.24)
pickle.dumps, d.values(), proto)[](#l2.25)
self.assertRaises((TypeError, pickle.PicklingError),[](#l2.26)
pickle.dumps, d.items(), proto)[](#l2.27)
+ if name == "main": unittest.main()
--- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -1,4 +1,6 @@ +import copy import gc +import pickle import sys import unittest import warnings @@ -111,6 +113,21 @@ class GeneratorTest(unittest.TestCase): self.assertEqual(gen.qualname, "GeneratorTest.test_name..")
- def test_copy(self):
def f():[](#l3.15)
yield 1[](#l3.16)
g = f()[](#l3.17)
with self.assertRaises(TypeError):[](#l3.18)
copy.copy(g)[](#l3.19)
- def test_pickle(self):
def f():[](#l3.22)
yield 1[](#l3.23)
g = f()[](#l3.24)
for proto in range(pickle.HIGHEST_PROTOCOL + 1):[](#l3.25)
with self.assertRaises((TypeError, pickle.PicklingError)):[](#l3.26)
pickle.dumps(g, proto)[](#l3.27)
+ class ExceptionTest(unittest.TestCase): # Tests for the issue #23353: check that the currently handled exception
--- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -5,6 +5,7 @@
For this purpose, the module-level "ET" symbol is temporarily
monkey-patched when running the "test_xml_etree_c" test suite.
+import copy import html import io import operator @@ -2082,6 +2083,19 @@ class ElementIterTest(unittest.TestCase) self.assertEqual(self._ilist(doc), all_tags) self.assertEqual(self._ilist(doc, '*'), all_tags)
- def test_copy(self):
a = ET.Element('a')[](#l4.16)
it = a.iter()[](#l4.17)
with self.assertRaises(TypeError):[](#l4.18)
copy.copy(it)[](#l4.19)
- def test_pickle(self):
a = ET.Element('a')[](#l4.22)
it = a.iter()[](#l4.23)
for proto in range(pickle.HIGHEST_PROTOCOL + 1):[](#l4.24)
with self.assertRaises((TypeError, pickle.PicklingError)):[](#l4.25)
pickle.dumps(it, proto)[](#l4.26)
+ class TreeBuilderTest(unittest.TestCase): sample1 = ('<!DOCTYPE html PUBLIC'
--- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -1,6 +1,7 @@ import unittest from test import support import binascii +import pickle import random import sys from test.support import bigmemtest, _1G, _4G @@ -600,6 +601,16 @@ class CompressObjectTestCase(BaseCompres d.flush() self.assertRaises(ValueError, d.copy)
- def test_compresspickle(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):[](#l5.16)
with self.assertRaises((TypeError, pickle.PicklingError)):[](#l5.17)
pickle.dumps(zlib.compressobj(zlib.Z_BEST_COMPRESSION), proto)[](#l5.18)
- def test_decompresspickle(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):[](#l5.21)
with self.assertRaises((TypeError, pickle.PicklingError)):[](#l5.22)
pickle.dumps(zlib.decompressobj(), proto)[](#l5.23)
+ # Memory use of the following functions takes into account overallocation @bigmemtest(size=_1G + 1024 * 1024, memuse=3)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -11,6 +11,9 @@ Release date: TBA Core and Builtins ----------------- +- Issue #22995: Default implementation of reduce and reduce_ex now
- Issue #25555: Fix parser and AST: fill lineno and col_offset of "arg" node when compiling AST from Python objects.
--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4100,6 +4100,12 @@ reduce_newobj(PyObject *obj, int proto) PyObject *newobj, *newargs, *state, *listitems, *dictitems; PyObject *result;