[pypy-svn] r26488 - in pypy/dist/pypy/rpython/ootypesystem: . test

nik at codespeak.net nik at codespeak.net
Fri Apr 28 05:52:59 CEST 2006


Author: nik
Date: Fri Apr 28 05:52:55 2006
New Revision: 26488

Modified:
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py
Log:
define a hash method on _views.


Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Fri Apr 28 05:52:55 2006
@@ -599,6 +599,9 @@
         assert isinstance(other, _view)
         return self._inst == other._inst
 
+    def __hash__(self):
+        return hash(self._inst)
+
     def __nonzero__(self):
         return bool(self._inst)
 

Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py	Fri Apr 28 05:52:55 2006
@@ -381,3 +381,13 @@
     assert a.zz() == 1
     assert b.zz() == 3
 
+def test_view_instance_hash():
+    I = Instance("Foo", ROOT)
+
+    inst = new(I)
+    inst_up = ooupcast(ROOT, inst)
+    inst_up2 = ooupcast(ROOT, inst)
+
+    assert inst_up == inst_up2
+    assert hash(inst_up) == hash(inst_up2)
+



More information about the Pypy-commit mailing list