Skip to content

Commit 0e2164e

Browse files
committed
fix pickling of class methods
1 parent 0c4d1de commit 0e2164e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/sage/misc/fpickle.pyx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ def call_pickled_function(fpargs):
124124
def pickleMethod(method):
125125
'support function for copyreg to pickle method refs'
126126

127-
# Note: On Python 3 there is no .im_class but we can get the instance's
128-
# class through .__self__.__class__
129-
cls = getattr(method, 'im_class', method.__self__.__class__)
127+
if isinstance(method.__self__, type):
128+
# This is a class method, so get it from the type directly
129+
return (getattr, (method.__self__, method.__func__.__name__))
130+
else:
131+
# Note: On Python 3 there is no .im_class but we can get the instance's
132+
# class through .__self__.__class__
133+
cls = getattr(method, 'im_class', method.__self__.__class__)
130134
return (unpickleMethod, (method.__func__.__name__, method.__self__, cls))
131135

132136

0 commit comments

Comments
 (0)