Skip to content

Commit

Permalink
gh-103092: Isolate _pickle module (#102982)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohamed Koubaa <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
  • Loading branch information
3 people authored Apr 4, 2023
1 parent 810d365 commit c00dcf0
Show file tree
Hide file tree
Showing 5 changed files with 703 additions and 669 deletions.
28 changes: 28 additions & 0 deletions Lib/test/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,34 @@ class CustomCPicklerClass(_pickle.Pickler, AbstractCustomPicklerClass):
pass
pickler_class = CustomCPicklerClass

@support.cpython_only
class HeapTypesTests(unittest.TestCase):
def setUp(self):
pickler = _pickle.Pickler(io.BytesIO())
unpickler = _pickle.Unpickler(io.BytesIO())

self._types = (
_pickle.Pickler,
_pickle.Unpickler,
type(pickler.memo),
type(unpickler.memo),

# We cannot test the _pickle.Pdata;
# there's no way to get to it.
)

def test_have_gc(self):
import gc
for tp in self._types:
with self.subTest(tp=tp):
self.assertTrue(gc.is_tracked(tp))

def test_immutable(self):
for tp in self._types:
with self.subTest(tp=tp):
with self.assertRaisesRegex(TypeError, "immutable"):
tp.foo = "bar"

@support.cpython_only
class SizeofTests(unittest.TestCase):
check_sizeof = support.check_sizeof
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adapt :mod:`!_pickle` to :pep:`687`. Patch by Mohamed Koubaa and Erlend Aasland.
Loading

0 comments on commit c00dcf0

Please sign in to comment.