Skip to content

cloudpickle cannot save bound classmethods for python2.7 #288

Description

@pierreglaser
In [1]: importcloudpickle
...: classA:
...: @classmethod
...: deff(cls):
...: pass
...: cloudpickle.dumps(A.f)

gives

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-b09b8cb46375> in <module>()
4deff(cls):
5pass
----> 6 cloudpickle.dumps(A.f)
/home/pierreglaser/.virtualenvs/py27/local/lib/python2.7/site-packages/cloudpickle/cloudpickle.pyc in dumps(obj, protocol)
893try:
894 cp = CloudPickler(file, protocol=protocol)
--> 895 cp.dump(obj)
896returnfile.getvalue()
897finally:
/home/pierreglaser/.virtualenvs/py27/local/lib/python2.7/site-packages/cloudpickle/cloudpickle.pyc in dump(self, obj)
266self.inject_addons()
267try:
--> 268 return Pickler.dump(self, obj)
269exceptRuntimeErroras e:
270if'recursion'in e.args[0]:
/usr/lib/python2.7/pickle.py in dump(self, obj)
222ifself.proto >=2:
223self.write(PROTO+chr(self.proto))
--> 224 self.save(obj)
225self.write(STOP)
226 /usr/lib/python2.7/pickle.py in save(self, obj)
284 f =self.dispatch.get(t)
285if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287return288 /home/pierreglaser/.virtualenvs/py27/local/lib/python2.7/site-packages/cloudpickle/cloudpickle.pyc in save_instancemethod(self, obj)
667self.save_reduce(types.MethodType, (obj.__func__, obj.__self__), obj=obj)
668else:
--> 669 self.save_reduce(types.MethodType, (obj.__func__, obj.__self__, obj.__self__.__class__),
670 obj=obj)
671AttributeError: class A has no attribute '__class__'

This does not seem to be a regression. The bug is present for any version of cloudpickle.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions