Skip to content

gh-136285: Improve pickle protocol testing in test_interpreters #136286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Lib/concurrent/interpreters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,8 @@ def __del__(self):
self._decref()

# for pickling:
def __getnewargs__(self):
return (self._id,)

# for pickling:
def __getstate__(self):
return None
def __reduce__(self):
return (type(self), (self._id,))

def _decref(self):
if not self._ownsref:
Expand Down
8 changes: 2 additions & 6 deletions Lib/concurrent/interpreters/_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ def __hash__(self):
return hash(self._id)

# for pickling:
def __getnewargs__(self):
return (self._id,)

# for pickling:
def __getstate__(self):
return None
def __reduce__(self):
return (type(self), (self._id,))

def _set_unbound(self, op, items=None):
assert not hasattr(self, '_unbound')
Expand Down
8 changes: 2 additions & 6 deletions Lib/test/support/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,8 @@ def __eq__(self, other):
return other._id == self._id

# for pickling:
def __getnewargs__(self):
return (int(self._id),)

# for pickling:
def __getstate__(self):
return None
def __reduce__(self):
return (type(self), (int(self._id),))

@property
def id(self):
Expand Down
8 changes: 5 additions & 3 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ def test_equality(self):

def test_pickle(self):
interp = interpreters.create()
data = pickle.dumps(interp)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, interp)
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(protocol=protocol):
data = pickle.dumps(interp, protocol)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, interp)


class TestInterpreterIsRunning(TestBase):
Expand Down
16 changes: 10 additions & 6 deletions Lib/test/test_interpreters/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ def test_equality(self):

def test_pickle(self):
ch, _ = channels.create()
data = pickle.dumps(ch)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, ch)
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(protocol=protocol):
data = pickle.dumps(ch, protocol)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, ch)


class TestSendChannelAttrs(TestBase):
Expand Down Expand Up @@ -152,9 +154,11 @@ def test_equality(self):

def test_pickle(self):
_, ch = channels.create()
data = pickle.dumps(ch)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, ch)
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(protocol=protocol):
data = pickle.dumps(ch, protocol)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, ch)


class TestSendRecv(TestBase):
Expand Down
8 changes: 5 additions & 3 deletions Lib/test/test_interpreters/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ def test_equality(self):

def test_pickle(self):
queue = queues.create()
data = pickle.dumps(queue)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, queue)
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(protocol=protocol):
data = pickle.dumps(queue, protocol)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, queue)


class TestQueueOps(TestBase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix pickling failures for protocols 0 and 1 for many objects realted to
subinterpreters.
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy