mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #22995: Instances of extension types with a state that aren't
subclasses of list or dict and haven't implemented any pickle-related methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__, or __getstate__), can no longer be pickled. Including memoryview.
This commit is contained in:
parent
bc4ded9537
commit
f81be8aa3f
4 changed files with 67 additions and 15 deletions
|
@ -1,6 +1,7 @@
|
|||
# Copyright (C) 2001,2002 Python Software Foundation
|
||||
# csv package unit tests
|
||||
|
||||
import copy
|
||||
import io
|
||||
import sys
|
||||
import os
|
||||
|
@ -9,6 +10,7 @@ from io import StringIO
|
|||
from tempfile import TemporaryFile
|
||||
import csv
|
||||
import gc
|
||||
import pickle
|
||||
from test import support
|
||||
|
||||
class Test_Csv(unittest.TestCase):
|
||||
|
@ -424,6 +426,17 @@ class TestDialectRegistry(unittest.TestCase):
|
|||
self.assertRaises(TypeError, csv.reader, [], quoting = -1)
|
||||
self.assertRaises(TypeError, csv.reader, [], quoting = 100)
|
||||
|
||||
def test_copy(self):
|
||||
for name in csv.list_dialects():
|
||||
dialect = csv.get_dialect(name)
|
||||
self.assertRaises(TypeError, copy.copy, dialect)
|
||||
|
||||
def test_pickle(self):
|
||||
for name in csv.list_dialects():
|
||||
dialect = csv.get_dialect(name)
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
self.assertRaises(TypeError, pickle.dumps, dialect, proto)
|
||||
|
||||
class TestCsvBase(unittest.TestCase):
|
||||
def readerAssertEqual(self, input, expected_result):
|
||||
with TemporaryFile("w+", newline='') as fileobj:
|
||||
|
|
|
@ -11,6 +11,8 @@ import gc
|
|||
import weakref
|
||||
import array
|
||||
import io
|
||||
import copy
|
||||
import pickle
|
||||
|
||||
|
||||
class AbstractMemoryTests:
|
||||
|
@ -519,6 +521,17 @@ class OtherTest(unittest.TestCase):
|
|||
m2 = m1[::-1]
|
||||
self.assertEqual(m2.hex(), '30' * 200000)
|
||||
|
||||
def test_copy(self):
|
||||
m = memoryview(b'abc')
|
||||
with self.assertRaises(TypeError):
|
||||
copy.copy(m)
|
||||
|
||||
def test_pickle(self):
|
||||
m = memoryview(b'abc')
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
with self.assertRaises(TypeError):
|
||||
pickle.dumps(m, proto)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue