当前位置: 首页>>代码示例>>Python>>正文


Python annrpython.RPythonAnnotator类代码示例

本文整理汇总了Python中pypy.annotation.annrpython.RPythonAnnotator的典型用法代码示例。如果您正苦于以下问题:Python RPythonAnnotator类的具体用法?Python RPythonAnnotator怎么用?Python RPythonAnnotator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RPythonAnnotator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_unbox

 def test_unbox(self):
     def fn():
         x = box(42)
         return unbox(x, ootype.Signed)
     a = RPythonAnnotator()
     s = a.build_types(fn, [])
     assert isinstance(s, annmodel.SomeInteger)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:test_dotnet.py

示例2: test_annotate_1

def test_annotate_1():
    def f():
        return eraseX(X())

    a = RPythonAnnotator()
    s = a.build_types(f, [])
    assert isinstance(s, SomeErased)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_rerased.py

示例3: test_annotate_erasing_pair

def test_annotate_erasing_pair():
    erase, unerase = new_erasing_pair("test1")
    erase2, unerase2 = new_erasing_pair("test2")

    class Foo:
        pass

    #
    def make(n):
        if n > 5:
            return erase([5, 6, n - 6])
        else:
            foo = Foo()
            foo.bar = n + 1
            return erase2(foo)

    def check(x, n):
        if n > 5:
            return unerase(x)[2]
        else:
            return unerase2(x).bar

    def f(n):
        x = make(n)
        return check(x, n)

    #
    a = RPythonAnnotator()
    s = a.build_types(f, [int])
    assert isinstance(s, annmodel.SomeInteger)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:30,代码来源:test_rerased.py

示例4: test_global

def test_global():
    def access_global():
        return glob_b.a
    
    a = RPythonAnnotator()
    s = a.build_types(access_global, [])
    assert s.knowntype is int
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:test_bltann.py

示例5: test_isinstance

def test_isinstance():
    class A:
        _alloc_flavor_ = "raw"
    class B(A):
        pass
    class C(B):
        pass
    
    def f(i):
        if i == 0:
            o = None
        elif i == 1:
            o = A()
        elif i == 2:
            o = B()
        else:
            o = C()
        return 100*isinstance(o, A)+10*isinstance(o, B)+1*isinstance(o ,C)

    a = RPythonAnnotator()
    #does not raise:
    s = a.build_types(f, [int])
    assert s.knowntype == int
    rtyper = RPythonTyper(a)
    rtyper.specialize()
    res = interpret(f, [1])
    assert res == 100
    res = interpret(f, [2])
    assert res == 110
    res = interpret(f, [3])
    assert res == 111
    res = interpret(f, [0])
    assert res == 0
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:test_nongc.py

示例6: test_new_bltn

def test_new_bltn():
    def new():
        return C()
    
    a = RPythonAnnotator()
    s = a.build_types(new, [])
    assert s.knowntype is C
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:test_bltann.py

示例7: test_annotate_lock

def test_annotate_lock():
    def fn():
        return thread.allocate_lock().acquire(False)
    a = RPythonAnnotator()
    s = a.build_types(fn, [])
    # result should be a boolean
    assert s.knowntype == bool
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_ll_thread.py

示例8: test_annotate_prebuilt_int

def test_annotate_prebuilt_int():
    e1 = erase_int(42)
    def f(i):
        return unerase_int(e1)
    a = RPythonAnnotator()
    s = a.build_types(f, [int])
    assert isinstance(s, annmodel.SomeInteger)
开发者ID:ieure,项目名称:pypy,代码行数:7,代码来源:test_rerased.py

示例9: test_fullname

 def test_fullname(self):
     def fn():
         return CLR.System.Math
     a = RPythonAnnotator()
     s = a.build_types(fn, [])
     assert isinstance(s, SomeCliClass)
     assert s.const is System.Math
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:test_dotnet.py

示例10: test_string

def test_string():
    def oof():
        return new(String)

    a = RPythonAnnotator()
    s = a.build_types(oof, [])
    assert s == annmodel.SomeOOInstance(String)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_ooann.py

示例11: test_class

 def test_class(self):
     def fn():
         return Math
     a = RPythonAnnotator()
     s = a.build_types(fn, [])
     assert isinstance(s, SomeCliClass)
     assert s.const is Math
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_dotnet.py

示例12: test_callback

    def test_callback(self):
        """
        Verify annotation when a callback function is in the arguments list.
        """

        def d(y):
            return eval("y()")

        class DTestFuncEntry(ExtFuncEntry):
            _about_ = d
            name = "d"
            signature_args = [annmodel.SomeGenericCallable(args=[], result=annmodel.SomeFloat())]
            signature_result = annmodel.SomeFloat()

        def callback():
            return 2.5

        def f():
            return d(callback)

        policy = AnnotatorPolicy()
        policy.allow_someobjects = False
        a = RPythonAnnotator(policy=policy)
        s = a.build_types(f, [])
        assert isinstance(s, annmodel.SomeFloat)
        assert a.translator._graphof(callback)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:26,代码来源:test_extfunc.py

示例13: test_raw_malloc

 def test_raw_malloc(self):
     def f():
         return raw_malloc(100)
     a = RPythonAnnotator()
     s = a.build_types(f, [])
     assert isinstance(s, annmodel.SomeAddress)
     assert not s.is_null
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_address.py

示例14: test_basic

    def test_basic(self):
        """
        A ExtFuncEntry provides an annotation for a function, no need to flow
        its graph.
        """

        def b(x):
            "NOT_RPYTHON"
            return eval("x+40")

        class BTestFuncEntry(ExtFuncEntry):
            _about_ = b
            name = "b"
            signature_args = [annmodel.SomeInteger()]
            signature_result = annmodel.SomeInteger()

        def f():
            return b(2)

        policy = AnnotatorPolicy()
        policy.allow_someobjects = False
        a = RPythonAnnotator(policy=policy)
        s = a.build_types(f, [])
        assert isinstance(s, annmodel.SomeInteger)

        res = interpret(f, [])
        assert res == 42
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:27,代码来源:test_extfunc.py

示例15: test_raw_free

 def test_raw_free(self):
     def f(addr):
         raw_free(addr)
     a = RPythonAnnotator()
     s = a.build_types(f, [annmodel.SomeAddress()])
     rtyper = RPythonTyper(a)
     rtyper.specialize() #does not raise
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_address.py


注:本文中的pypy.annotation.annrpython.RPythonAnnotator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。