Skip to content

Commit c00dcf0

Browse files
erlend-aaslandkoubaakumaraditya303
authored
gh-103092: Isolate _pickle module (#102982)
Co-authored-by: Mohamed Koubaa <[email protected]> Co-authored-by: Kumar Aditya <[email protected]>
1 parent 810d365 commit c00dcf0

File tree

5 files changed

+703
-669
lines changed

5 files changed

+703
-669
lines changed

Lib/test/test_pickle.py

+28
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,34 @@ class CustomCPicklerClass(_pickle.Pickler, AbstractCustomPicklerClass):
293293
pass
294294
pickler_class = CustomCPicklerClass
295295

296+
@support.cpython_only
297+
class HeapTypesTests(unittest.TestCase):
298+
def setUp(self):
299+
pickler = _pickle.Pickler(io.BytesIO())
300+
unpickler = _pickle.Unpickler(io.BytesIO())
301+
302+
self._types = (
303+
_pickle.Pickler,
304+
_pickle.Unpickler,
305+
type(pickler.memo),
306+
type(unpickler.memo),
307+
308+
# We cannot test the _pickle.Pdata;
309+
# there's no way to get to it.
310+
)
311+
312+
def test_have_gc(self):
313+
import gc
314+
for tp in self._types:
315+
with self.subTest(tp=tp):
316+
self.assertTrue(gc.is_tracked(tp))
317+
318+
def test_immutable(self):
319+
for tp in self._types:
320+
with self.subTest(tp=tp):
321+
with self.assertRaisesRegex(TypeError, "immutable"):
322+
tp.foo = "bar"
323+
296324
@support.cpython_only
297325
class SizeofTests(unittest.TestCase):
298326
check_sizeof = support.check_sizeof
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adapt :mod:`!_pickle` to :pep:`687`. Patch by Mohamed Koubaa and Erlend Aasland.

0 commit comments

Comments
 (0)