Skip to content

Commit

Permalink
Add more notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Aug 6, 2024
1 parent 20b030f commit 5b777b6
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 32 deletions.
28 changes: 16 additions & 12 deletions Lib/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,18 +600,22 @@ def save(self, obj, save_persistent_id=True):
self.save_global(obj, rv)
return

# Assert that reduce() returned a tuple
if not isinstance(rv, tuple):
raise PicklingError("%s must return string or tuple" % reduce)

# Assert that it returned an appropriately sized tuple
l = len(rv)
if not (2 <= l <= 6):
raise PicklingError("Tuple returned by %s must have "
"two to six elements" % reduce)

# Save the reduce() output and finally memoize the object
self.save_reduce(obj=obj, *rv)
try:
# Assert that reduce() returned a tuple
if not isinstance(rv, tuple):
raise PicklingError("%s must return string or tuple" % reduce)

# Assert that it returned an appropriately sized tuple
l = len(rv)
if not (2 <= l <= 6):
raise PicklingError("Tuple returned by %s must have "
"two to six elements" % reduce)

# Save the reduce() output and finally memoize the object
self.save_reduce(obj=obj, *rv)
except BaseException as exc:
exc.add_note(f'when serializing {_T(obj)} object')
raise

def persistent_id(self, obj):
# This exists so a subclass can override it
Expand Down
Loading

0 comments on commit 5b777b6

Please sign in to comment.