[pypy-svn] r36673 - pypy/dist/pypy/rpython/ootypesystem

fijal at codespeak.net fijal at codespeak.net
Sat Jan 13 17:08:50 CET 2007


Author: fijal
Date: Sat Jan 13 17:08:49 2007
New Revision: 36673

Modified:
   pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
Log:
Slight fix to avoid usage of instance


Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py	Sat Jan 13 17:08:49 2007
@@ -37,6 +37,18 @@
     
     _is_compatible = staticmethod(_is_compatible)
 
+def typeof(val):
+    """ Small wrapper, which tries to resemble example -> python type
+    which can go to annotation path
+    """
+    if isinstance(val, list):
+        return [typeof(val[0])]
+    if isinstance(val, dict):
+        return {typeof(val.keys()[0]):typeof(val.values()[0])}
+    if isinstance(val, tuple):
+        return tuple([typeof(i) for i in val])
+    return type(val)
+
 class BasicExternal(object):
     __metaclass__ = BasicMetaExternal
     __self__ = None
@@ -45,7 +57,6 @@
     _methods = {}
     
     def described(retval=None, args={}):
-        xxx # we'll fix that later
         def decorator(func):
             code = func.func_code
             if not func.func_defaults:
@@ -65,7 +76,7 @@
                 if varname in args:
                     arg_pass.append((varname, args[varname]))
                 else:
-                    arg_pass.append((varname, defs[arg - start_pos]))
+                    arg_pass.append((varname, typeof(defs[arg - start_pos])))
             func._method = (func.__name__, MethodDesc(arg_pass, retval))
             return func
         return decorator
@@ -165,7 +176,7 @@
     
     def compute_annotation(self):
         return annmodel.SomeExternalBuiltin(self.bookkeeper.getexternaldesc\
-            (self.instance.__class__))
+            (self.type))
     
     def get_field_annotation(self, ext_obj, attr):
         return ext_obj.get_field(attr)



More information about the Pypy-commit mailing list