Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix pickling bug
  • Loading branch information
sobolevn committed Jul 5, 2025
commit 8b6fbdec846eeea53a597ec46340712edecb5471
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
2 changes: 1 addition & 1 deletion Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def test_equality(self):

def test_pickle(self):
interp = interpreters.create()
for protocol in range(2, pickle.HIGHEST_PROTOCOL + 1):
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(protocol=protocol):
data = pickle.dumps(interp, protocol)
unpickled = pickle.loads(data)
Expand Down
15 changes: 8 additions & 7 deletions Lib/test/test_interpreters/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ def test_equality(self):
self.assertNotEqual(ch1, ch2)

def test_pickle(self):
ch, _ = channels.create()
for protocol in range(2, pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(protocol=protocol):
data = pickle.dumps(ch, protocol)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, ch)
recv, send = channels.create()
for ch in [recv, send]:
Comment thread
sobolevn marked this conversation as resolved.
Outdated
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(ch=ch, protocol=protocol):
data = pickle.dumps(ch, protocol)
unpickled = pickle.loads(data)
self.assertEqual(unpickled, ch)


class TestSendChannelAttrs(TestBase):
Expand Down Expand Up @@ -154,7 +155,7 @@ def test_equality(self):

def test_pickle(self):
_, ch = channels.create()
for protocol in range(2, pickle.HIGHEST_PROTOCOL + 1):
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(protocol=protocol):
data = pickle.dumps(ch, protocol)
unpickled = pickle.loads(data)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_interpreters/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_equality(self):

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