@@ -19,21 +19,33 @@ public class PyMethod extends PyObject {
1919 @ ExposedGet (doc = BuiltinDocs .instancemethod_im_class_doc )
2020 public PyObject im_class ;
2121
22- /** The function (or other callable) implementing a method. */
23- @ ExposedGet (doc = BuiltinDocs .instancemethod_im_func_doc )
24- public PyObject im_func ;
22+ /** The function (or other callable) implementing a method, also available via im_func */
23+ @ ExposedGet (doc = BuiltinDocs .instancemethod___func___doc )
24+ public PyObject __func__ ;
2525
26- /** The instance to which a method is bound; None for unbound methods. */
27- @ ExposedGet (doc = BuiltinDocs .instancemethod_im_self_doc )
28- public PyObject im_self ;
26+ /** The instance to which a method is bound; None for unbound methods also available via im_self */
27+ @ ExposedGet (doc = BuiltinDocs .instancemethod___self___doc )
28+ public PyObject __self__ ;
29+
30+ @ Deprecated
31+ @ ExposedGet (name = "im_func" )
32+ public PyObject getFunc () {
33+ return __func__ ;
34+ }
35+
36+ @ Deprecated
37+ @ ExposedGet (name = "im_self" )
38+ public PyObject getSelf () {
39+ return __self__ ;
40+ }
2941
3042 public PyMethod (PyObject function , PyObject self , PyObject type ) {
3143 super (TYPE );
3244 if (self == Py .None ){
3345 self = null ;
3446 }
35- im_func = function ;
36- im_self = self ;
47+ __func__ = function ;
48+ __self__ = self ;
3749 im_class = type ;
3850 }
3951
@@ -65,7 +77,7 @@ final PyObject instancemethod___findattr_ex__(String name) {
6577 if (ret != null ) {
6678 return ret ;
6779 }
68- return im_func .__findattr_ex__ (name );
80+ return __func__ .__findattr_ex__ (name );
6981 }
7082
7183 @ ExposedMethod (doc = BuiltinDocs .instancemethod___getattribute___doc )
@@ -86,10 +98,10 @@ public PyObject __get__(PyObject obj, PyObject type) {
8698 @ ExposedMethod (defaults = "null" , doc = BuiltinDocs .instancemethod___get___doc )
8799 final PyObject instancemethod___get__ (PyObject obj , PyObject type ) {
88100 // Only if classes are compatible
89- if (obj == null || im_self != null ) {
101+ if (obj == null || __self__ != null ) {
90102 return this ;
91103 } else if (Py .isSubClass (obj .fastGetClass (), im_class )) {
92- return new PyMethod (im_func , obj , im_class );
104+ return new PyMethod (__func__ , obj , im_class );
93105 } else {
94106 return this ;
95107 }
@@ -104,9 +116,9 @@ public PyObject __call__() {
104116 public PyObject __call__ (ThreadState state ) {
105117 PyObject self = checkSelf (null , null );
106118 if (self == null ) {
107- return im_func .__call__ (state );
119+ return __func__ .__call__ (state );
108120 } else {
109- return im_func .__call__ (state , self );
121+ return __func__ .__call__ (state , self );
110122 }
111123 }
112124
@@ -119,9 +131,9 @@ public PyObject __call__(PyObject arg0) {
119131 public PyObject __call__ (ThreadState state , PyObject arg0 ) {
120132 PyObject self = checkSelf (arg0 , null );
121133 if (self == null ) {
122- return im_func .__call__ (state , arg0 );
134+ return __func__ .__call__ (state , arg0 );
123135 } else {
124- return im_func .__call__ (state , self , arg0 );
136+ return __func__ .__call__ (state , self , arg0 );
125137 }
126138 }
127139
@@ -134,9 +146,9 @@ public PyObject __call__(PyObject arg0, PyObject arg1) {
134146 public PyObject __call__ (ThreadState state , PyObject arg0 , PyObject arg1 ) {
135147 PyObject self = checkSelf (arg0 , null );
136148 if (self == null ) {
137- return im_func .__call__ (state , arg0 , arg1 );
149+ return __func__ .__call__ (state , arg0 , arg1 );
138150 } else {
139- return im_func .__call__ (state , self , arg0 , arg1 );
151+ return __func__ .__call__ (state , self , arg0 , arg1 );
140152 }
141153 }
142154
@@ -149,9 +161,9 @@ public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) {
149161 public PyObject __call__ (ThreadState state , PyObject arg0 , PyObject arg1 , PyObject arg2 ) {
150162 PyObject self = checkSelf (arg0 , null );
151163 if (self == null ) {
152- return im_func .__call__ (state , arg0 , arg1 , arg2 );
164+ return __func__ .__call__ (state , arg0 , arg1 , arg2 );
153165 } else {
154- return im_func .__call__ (state , self , arg0 , arg1 , arg2 );
166+ return __func__ .__call__ (state , self , arg0 , arg1 , arg2 );
155167 }
156168 }
157169
@@ -165,9 +177,9 @@ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObje
165177 PyObject arg3 ) {
166178 PyObject self = checkSelf (arg0 , null );
167179 if (self == null ) {
168- return im_func .__call__ (state , arg0 , arg1 , arg2 , arg3 );
180+ return __func__ .__call__ (state , arg0 , arg1 , arg2 , arg3 );
169181 } else {
170- return im_func .__call__ (state , self , new PyObject []{arg0 , arg1 , arg2 , arg3 },
182+ return __func__ .__call__ (state , self , new PyObject []{arg0 , arg1 , arg2 , arg3 },
171183 Py .NoKeywords );
172184 }
173185 }
@@ -182,12 +194,12 @@ public PyObject __call__(ThreadState state, PyObject arg1, PyObject[] args,
182194 String [] keywords ) {
183195 PyObject self = checkSelf (arg1 , args );
184196 if (self == null ) {
185- return im_func .__call__ (state , arg1 , args , keywords );
197+ return __func__ .__call__ (state , arg1 , args , keywords );
186198 } else {
187199 PyObject [] newArgs = new PyObject [args .length + 1 ];
188200 System .arraycopy (args , 0 , newArgs , 1 , args .length );
189201 newArgs [0 ] = arg1 ;
190- return im_func .__call__ (state , self , newArgs , keywords );
202+ return __func__ .__call__ (state , self , newArgs , keywords );
191203 }
192204 }
193205
@@ -215,14 +227,14 @@ public PyObject __call__(ThreadState state, PyObject[] args, String[] keywords)
215227 final PyObject instancemethod___call__ (ThreadState state , PyObject [] args , String [] keywords ) {
216228 PyObject self = checkSelf (null , args );
217229 if (self == null ) {
218- return im_func .__call__ (state , args , keywords );
230+ return __func__ .__call__ (state , args , keywords );
219231 } else {
220- return im_func .__call__ (state , self , args , keywords );
232+ return __func__ .__call__ (state , self , args , keywords );
221233 }
222234 }
223235
224236 private PyObject checkSelf (PyObject arg , PyObject [] args ) {
225- PyObject self = im_self ;
237+ PyObject self = __self__ ;
226238 if (self == null ) {
227239 // Unbound methods must be called with an instance of the
228240 // class (or a derived class) as first argument
@@ -264,30 +276,30 @@ final int instancemethod___cmp__(PyObject other) {
264276 return -2 ;
265277 }
266278 PyMethod otherMethod = (PyMethod )other ;
267- int cmp = im_func ._cmp (otherMethod .im_func );
279+ int cmp = __func__ ._cmp (otherMethod .__func__ );
268280 if (cmp != 0 ) {
269281 return cmp ;
270282 }
271- if (im_self == otherMethod .im_self ) {
283+ if (__self__ == otherMethod .__self__ ) {
272284 return 0 ;
273285 }
274- if (im_self == null || otherMethod .im_self == null ) {
275- return System .identityHashCode (im_self ) < System .identityHashCode (otherMethod .im_self )
286+ if (__self__ == null || otherMethod .__self__ == null ) {
287+ return System .identityHashCode (__self__ ) < System .identityHashCode (otherMethod .__self__ )
276288 ? -1 : 1 ;
277289 } else {
278- return im_self ._cmp (otherMethod .im_self );
290+ return __self__ ._cmp (otherMethod .__self__ );
279291 }
280292 }
281293
282294 @ Override
283295 public int hashCode () {
284- int hashCode = im_self == null ? Py .None .hashCode () : im_self .hashCode ();
285- return hashCode ^ im_func .hashCode ();
296+ int hashCode = __self__ == null ? Py .None .hashCode () : __self__ .hashCode ();
297+ return hashCode ^ __func__ .hashCode ();
286298 }
287299
288300 @ ExposedGet (name = "__doc__" )
289301 public PyObject getDoc () {
290- return im_func .__getattr__ ("__doc__" );
302+ return __func__ .__getattr__ ("__doc__" );
291303 }
292304
293305 @ Override
@@ -296,11 +308,11 @@ public String toString() {
296308 if (im_class != null ) {
297309 className = getClassName (im_class );
298310 }
299- if (im_self == null ) {
311+ if (__self__ == null ) {
300312 return String .format ("<unbound method %s.%s>" , className , getFuncName ());
301313 } else {
302314 return String .format ("<bound method %s.%s of %s>" , className , getFuncName (),
303- im_self .__str__ ());
315+ __self__ .__str__ ());
304316 }
305317 }
306318
@@ -328,7 +340,7 @@ private String getInstClassName(PyObject inst) {
328340 private String getFuncName () {
329341 PyObject funcName = null ;
330342 try {
331- funcName = im_func .__findattr__ ("__name__" );
343+ funcName = __func__ .__findattr__ ("__name__" );
332344 } catch (PyException pye ) {
333345 // continue
334346 }
0 commit comments