File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed
Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,27 @@ def test_functiontype_from_globals(self):
3030 self .assertEquals (sm_abc (), 789 )
3131
3232
33+ class MethodHashCodeTestCase (unittest .TestCase ):
34+
35+ def test_builtin_method_hashcode (self ):
36+ foo = 'foo'
37+ self .assert_ (foo .title is not foo .title )
38+ self .assertEqual (hash (foo .title ), hash (foo .title ))
39+ self .assertNotEqual (hash (foo .title ), hash ('bar' .title ))
40+
41+ def test_method_hashcode (self ):
42+ class Foo (object ):
43+ def bar (self ):
44+ pass
45+ foo = Foo ()
46+ self .assert_ (foo .bar is not foo .bar )
47+ self .assertEqual (hash (foo .bar ), hash (foo .bar ))
48+ self .assertNotEqual (hash (foo .bar ), hash (Foo ().bar ))
49+
50+
3351def test_main ():
34- test_support .run_unittest (FunctionTypeTestCase )
52+ test_support .run_unittest (FunctionTypeTestCase ,
53+ MethodHashCodeTestCase )
3554
3655if __name__ == '__main__' :
3756 test_main ()
Original file line number Diff line number Diff line change 22
33import org .python .expose .ExposeAsSuperclass ;
44
5-
65public abstract class PyBuiltinMethod extends PyBuiltinFunction implements ExposeAsSuperclass {
76
7+ protected PyObject self ;
8+
89 protected PyBuiltinMethod (PyType type , PyObject self , Info info ) {
910 super (type , info );
1011 this .self = self ;
1112 }
13+
1214 protected PyBuiltinMethod (PyObject self , Info info ) {
1315 super (info );
1416 this .self = self ;
@@ -26,5 +28,9 @@ public PyMethodDescr makeDescriptor(PyType t) {
2628 return new PyMethodDescr (t , this );
2729 }
2830
29- protected PyObject self ;
31+ @ Override
32+ public int hashCode () {
33+ int hashCode = self == null ? 0 : self .hashCode ();
34+ return hashCode ^ getClass ().hashCode ();
35+ }
3036}
Original file line number Diff line number Diff line change @@ -136,6 +136,12 @@ final int instancemethod___cmp__(PyObject other) {
136136 return 0 ;
137137 }
138138
139+ @ Override
140+ public int hashCode () {
141+ int hashCode = im_self == null ? Py .None .hashCode () : im_self .hashCode ();
142+ return hashCode ^ im_func .hashCode ();
143+ }
144+
139145 @ Override
140146 public PyObject getDoc () {
141147 return im_func .getDoc ();
You can’t perform that action at this time.
0 commit comments