Skip to content

Commit 1c4a223

Browse files
committed
remove python 2 compat code in pickleMethod and unpickleMethod
1 parent 4641801 commit 1c4a223

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/sage/misc/fpickle.pyx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ def pickleMethod(method):
128128
# This is a class method, so get it from the type directly
129129
return (getattr, (method.__self__, method.__func__.__name__))
130130
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__)
134-
return (unpickleMethod, (method.__func__.__name__, method.__self__, cls))
131+
cls = method.__self__.__class__
132+
return (unpickleMethod, (method.__func__.__name__, method.__self__, cls))
135133

136134

137135
def unpickleMethod(im_name,
@@ -143,22 +141,16 @@ def unpickleMethod(im_name,
143141
if __self__ is None:
144142
return unbound
145143

146-
# Note: On Python 2 "unbound methods" are just functions, so they don't
147-
# have a __func__
148-
bound = types.MethodType(getattr(unbound, '__func__', unbound),
149-
__self__)
144+
bound = types.MethodType(unbound, __self__)
150145
return bound
151146
except AttributeError:
152147
assert __self__ is not None, "No recourse: no instance to guess from."
153148
# Attempt a common fix before bailing -- if classes have
154149
# changed around since we pickled this method, we may still be
155150
# able to get it by looking on the instance's current class.
156151
unbound = getattr(__self__.__class__, im_name)
157-
if __self__ is None:
158-
return unbound
159152

160-
bound = types.MethodType(getattr(unbound, '__func__', unbound),
161-
__self__)
153+
bound = types.MethodType(unbound, __self__)
162154
return bound
163155

164156

0 commit comments

Comments
 (0)