Skip to content
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

Save bound classmethod py27 #289

Merged
merged 3 commits into from
Jun 12, 2019
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.2.2
=====

- Fix a bug affecting bound classmethod saving on Python 2.
([issue #288](https://github.com/cloudpipe/cloudpickle/issues/288))

1.2.1
=====
Expand Down
2 changes: 1 addition & 1 deletion cloudpickle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
if sys.version_info[:2] >= (3, 8):
from cloudpickle.cloudpickle_fast import CloudPickler, dumps, dump

__version__ = '1.3.0.dev0'
__version__ = '1.2.2.dev0'
5 changes: 3 additions & 2 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,9 @@ def save_instancemethod(self, obj):
if PY3: # pragma: no branch
self.save_reduce(types.MethodType, (obj.__func__, obj.__self__), obj=obj)
else:
self.save_reduce(types.MethodType, (obj.__func__, obj.__self__, obj.__self__.__class__),
obj=obj)
self.save_reduce(
types.MethodType,
(obj.__func__, obj.__self__, type(obj.__self__)), obj=obj)

dispatch[types.MethodType] = save_instancemethod

Expand Down
9 changes: 9 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ def test_cm(cls):
self.assertEqual(A.test_sm(), "sm")
self.assertEqual(A.test_cm(), "cm")

def test_bound_classmethod(self):
class A:
@classmethod
def test_cm(cls):
return "cm"

A.test_cm = pickle_depickle(A.test_cm, protocol=self.protocol)
self.assertEqual(A.test_cm(), "cm")

def test_method_descriptors(self):
f = pickle_depickle(str.upper)
self.assertEqual(f('abc'), 'ABC')
Expand Down