[pypy-svn] r36508 - in pypy/dist/pypy/annotation: . test

fijal at codespeak.net fijal at codespeak.net
Thu Jan 11 16:57:07 CET 2007


Author: fijal
Date: Thu Jan 11 16:57:06 2007
New Revision: 36508

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/annotation/test/test_annrpython.py
   pypy/dist/pypy/annotation/unaryop.py
Log:
Add possibility to call SomeGenericCallable


Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Thu Jan 11 16:57:06 2007
@@ -409,6 +409,8 @@
             result = SomeOOClass(x._INSTANCE)   # NB. can be None
         elif isinstance(x, ootype.instance_impl): # XXX
             result = SomeOOInstance(ootype.typeOf(x))
+        elif hasattr(x, '_known_annotation_'):
+            result = x._known_annotation_
         elif callable(x):
             if hasattr(x, '__self__') and x.__self__ is not None:
                 # for cases like 'l.append' where 'l' is a global constant list

Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Thu Jan 11 16:57:06 2007
@@ -393,6 +393,12 @@
         else:
             return kt.__name__
 
+class SomeGenericCallable(SomeObject):
+    """ Stands for external callable with known signature
+    """
+    def __init__(self, args, retval):
+        self.args_s = args
+        self.retval_s = retval
 
 class SomeBuiltin(SomeObject):
     "Stands for a built-in function or method with special-cased analysis."

Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py	Thu Jan 11 16:57:06 2007
@@ -2451,26 +2451,24 @@
         assert s.const == 0
 
     def test_some_generic_function_call(self):
-        py.test.skip("Not implemented")
         def g(a):
             pass
-        g._known_signature_ = annmodel.SomeGenericFunction(
+        g._known_annotation_ = annmodel.SomeGenericCallable(
             args=(annmodel.SomeInteger(),), retval=annmodel.SomeInteger())
 
         def fun():
             return g(1)
         a = self.RPythonAnnotator(policy=policy.AnnotatorPolicy())
         s = a.build_types(fun, [])
-        assert isinstance(s.returntype, annmodel.SomeInteger)
-        assert not hasattr(s.returntype, 'const')
-        # assert that a know the g
+        assert isinstance(s, annmodel.SomeInteger)
+        assert not hasattr(s, 'const')
 
     def test_some_generic_function_callback(self):
         py.test.skip("Not implemented")
         def g(a):
             pass
-        g._known_signature_ = annmodel.SomeGenericFunction(
-            args=[annmodel.SomeGenericFunction(args=[SomeInteger()],
+        g._known_annotation_ = annmodel.SomeGenericCallable(
+            args=[annmodel.SomeGenericCallable(args=[SomeInteger()],
                                                retval=SomeInteger())])
 
         def fun2(x):

Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Thu Jan 11 16:57:06 2007
@@ -8,7 +8,8 @@
      SomeInstance, SomeBuiltin, SomeFloat, SomeIterator, SomePBC, \
      SomeExternalObject, SomeTypedAddressAccess, SomeAddress, \
      SomeCTypesObject, s_ImpossibleValue, s_Bool, \
-     unionof, set, missing_operation, add_knowntypedata, HarmlesslyBlocked
+     unionof, set, missing_operation, add_knowntypedata, HarmlesslyBlocked, \
+     SomeGenericCallable
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.annotation import builtin
 from pypy.annotation.binaryop import _clone ## XXX where to put this?
@@ -599,6 +600,12 @@
         elif not pbc.can_be_None:
             s.const = True
 
+class __extend__(SomeGenericCallable):
+    def call(self, args):
+        bookkeeper = getbookkeeper()
+        for arg, expected in zip(args.unpack()[0], self.args_s):
+            assert expected.contains(arg)
+        return self.retval_s
 
 class __extend__(SomeExternalObject):
     def find_method(obj, name):



More information about the Pypy-commit mailing list