Skip to content
Closed
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
9 changes: 6 additions & 3 deletions sdks/python/apache_beam/coders/coders.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def maybe_dill_dumps(o):
# We need to use the dill pickler for objects of certain custom classes,
# including, for example, ones that contain lambdas.
try:
return pickle.dumps(o)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use https://docs.python.org/2/library/pickle.html#pickle.HIGHEST_PROTOCOL to be more clear with the intent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return pickle.dumps(o, pickle.HIGHEST_PROTOCOL)
except Exception: # pylint: disable=broad-except
return dill.dumps(o)

Expand Down Expand Up @@ -426,7 +426,10 @@ class PickleCoder(_PickleCoderBase):
"""Coder using Python's pickle functionality."""

def _create_impl(self):
return coder_impl.CallbackCoderImpl(pickle.dumps, pickle.loads)
dumps = pickle.dumps
HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
return coder_impl.CallbackCoderImpl(
lambda x: dumps(x, HIGHEST_PROTOCOL), pickle.loads)


class DillCoder(_PickleCoderBase):
Expand Down Expand Up @@ -515,7 +518,7 @@ class Base64PickleCoder(Coder):
# than via a special Coder.

def encode(self, value):
return base64.b64encode(pickle.dumps(value))
return base64.b64encode(pickle.dumps(value, pickle.HIGHEST_PROTOCOL))

def decode(self, encoded):
return pickle.loads(base64.b64decode(encoded))
Expand Down