mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
rejects builtin types with not defined __new__. Added tests for non-pickleable types.
This commit is contained in:
commit
609a2e17ad
7 changed files with 99 additions and 0 deletions
|
@ -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
|
||||
coro = func()
|
||||
with self.assertRaises(TypeError):
|
||||
copy.copy(coro)
|
||||
|
||||
aw = coro.__await__()
|
||||
try:
|
||||
with self.assertRaises(TypeError):
|
||||
copy.copy(aw)
|
||||
finally:
|
||||
aw.close()
|
||||
|
||||
def test_pickle(self):
|
||||
async def func(): pass
|
||||
coro = func()
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
with self.assertRaises((TypeError, pickle.PicklingError)):
|
||||
pickle.dumps(coro, proto)
|
||||
|
||||
aw = coro.__await__()
|
||||
try:
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
with self.assertRaises((TypeError, pickle.PicklingError)):
|
||||
pickle.dumps(aw, proto)
|
||||
finally:
|
||||
aw.close()
|
||||
|
||||
|
||||
class CoroAsyncIOCompatTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue