@@ -128,10 +128,8 @@ def pickleMethod(method):
128
128
# This is a class method, so get it from the type directly
129
129
return (getattr , (method.__self__, method.__func__.__name__ ))
130
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__ )
134
- return (unpickleMethod, (method.__func__.__name__ , method.__self__, cls ))
131
+ cls = method.__self__.__class__
132
+ return (unpickleMethod, (method.__func__.__name__ , method.__self__, cls ))
135
133
136
134
137
135
def unpickleMethod (im_name ,
@@ -143,22 +141,16 @@ def unpickleMethod(im_name,
143
141
if __self__ is None :
144
142
return unbound
145
143
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__)
150
145
return bound
151
146
except AttributeError :
152
147
assert __self__ is not None , " No recourse: no instance to guess from."
153
148
# Attempt a common fix before bailing -- if classes have
154
149
# changed around since we pickled this method, we may still be
155
150
# able to get it by looking on the instance's current class.
156
151
unbound = getattr (__self__.__class__ , im_name)
157
- if __self__ is None :
158
- return unbound
159
152
160
- bound = types.MethodType(getattr (unbound, ' __func__' , unbound),
161
- __self__)
153
+ bound = types.MethodType(unbound, __self__)
162
154
return bound
163
155
164
156
0 commit comments