示例#1
0
class DTestFuncEntry(ExtFuncEntry):
    _about_ = d
    name = 'd'
    signature_args = [
        annmodel.SomeGenericCallable(args=[], result=annmodel.SomeFloat())
    ]
    signature_result = annmodel.SomeFloat()
示例#2
0
    def test_some_generic_function_call(self):
        def h(x):
            return int(x)

        def c(x):
            return int(x) + 1

        def default(x):
            return int(x) + 3

        def g(a, x):
            if x == -1:
                a = None
            if x > 0:
                if x == 1:
                    a = h
                else:
                    a = c
                x = x + 0.01
            return a(x)

        def f(x):
            return g(default, x)

        g._annenforceargs_ = policy.Sig(
            annmodel.SomeGenericCallable(args=[annmodel.SomeFloat()],
                                         result=annmodel.SomeInteger()), float)

        assert interpret(f, [1.]) == 1
        assert interpret(f, [10.]) == 11
        assert interpret(f, [-3.]) == 0
示例#3
0
class CC(BasicExternal):
    _methods = {
        'some_method':
        MethodDesc([
            annmodel.SomeGenericCallable(args=[annmodel.SomeInteger()],
                                         result=annmodel.SomeFloat())
        ], int)
    }
示例#4
0
class CB(BasicExternal):
    _fields = {
        'm': annmodel.SomeGenericCallable(args=[],
                                          result=annmodel.SomeInteger()),
    }
示例#5
0
class CD(BasicExternal):
    _fields = {
        'callback_field':
        annmodel.SomeGenericCallable([annmodel.SomeInteger()],
                                     annmodel.SomeFloat())
    }
示例#6
0
 def compute_result_annotation(self):
     from pypy.annotation import model as annmodel
     return annmodel.SomeGenericCallable([annotation(i, self.bookkeeper)
                                          for i in self.instance.args],
                        annotation(self.instance.result, self.bookkeeper))
示例#7
0
 def compute_annotation(self):
     bookkeeper = getbookkeeper()
     args_s = [annotation(i._type) for i in self.instance.args]
     s_result = annotation(self.instance.result._type)
     return annmodel.SomeGenericCallable(args=args_s, result=s_result)