[pypy-svn] r24867 - in pypy/branch/pypy-rdict-refactoring/rpython: . lltypesystem

arigo at codespeak.net arigo at codespeak.net
Thu Mar 23 11:09:59 CET 2006


Author: arigo
Date: Thu Mar 23 11:09:57 2006
New Revision: 24867

Modified:
   pypy/branch/pypy-rdict-refactoring/rpython/lltypesystem/lltype.py
   pypy/branch/pypy-rdict-refactoring/rpython/rdict.py
Log:
Argh!  staticmethod() is hashed by identity in CPython.  Bad surprize.
Need a custom version...


Modified: pypy/branch/pypy-rdict-refactoring/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/pypy-rdict-refactoring/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/pypy-rdict-refactoring/rpython/lltypesystem/lltype.py	Thu Mar 23 11:09:57 2006
@@ -1128,6 +1128,31 @@
     func._type_method = True
     return func
 
+class staticAdtMethod(object):
+    # Like staticmethod(), but for ADT methods.  The difference is only
+    # that this version compares and hashes correctly, unlike CPython's.
+    def __init__(self, obj):
+        self.obj = obj
+
+    def __get__(self, inst, typ=None):
+        return self.obj
+
+    def __hash__(self):
+        return hash(self.obj)
+
+    def __eq__(self, other):
+        if not isinstance(other, staticMethod):
+            return NotImplemented
+        else:
+            return self.obj == other.obj
+
+    def __ne__(self, other):
+        if not isinstance(other, staticMethod):
+            return NotImplemented
+        else:
+            return self.obj != other.obj
+
+
 def dissect_ll_instance(v, t=None, memo=None):
     if memo is None:
         memo = {}

Modified: pypy/branch/pypy-rdict-refactoring/rpython/rdict.py
==============================================================================
--- pypy/branch/pypy-rdict-refactoring/rpython/rdict.py	(original)
+++ pypy/branch/pypy-rdict-refactoring/rpython/rdict.py	Thu Mar 23 11:09:57 2006
@@ -199,9 +199,9 @@
                 # figure out which functions must be used to hash and compare
                 ll_keyhash = self.key_repr.get_ll_hash_function()
                 ll_keyeq = self.key_repr.get_ll_eq_function()  # can be None
-                ll_keyhash = staticmethod(ll_keyhash)
+                ll_keyhash = lltype.staticAdtMethod(ll_keyhash)
                 if ll_keyeq is not None:
-                    ll_keyeq = staticmethod(ll_keyeq)
+                    ll_keyeq = lltype.staticAdtMethod(ll_keyeq)
                 adtmeths = {
                     'keyhash': ll_keyhash,
                     'keyeq':   ll_keyeq,



More information about the Pypy-commit mailing list