• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python annrpython.RPythonAnnotator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_oostring_annotation

def test_oostring_annotation():
    def oof():
        return ootype.oostring

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


示例17: test_register_external_return_goes_back

    def test_register_external_return_goes_back(self):
        """
        Check whether it works to pass the same list from one external
        fun to another
        [bookkeeper and list joining issues]
        """

        def function_with_list():
            pass

        register_external(function_with_list, [[int]], int)

        def function_returning_list():
            pass

        register_external(function_returning_list, [], [int])

        def f():
            return function_with_list(function_returning_list())

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


示例18: test_oostring_result_annotation

def test_oostring_result_annotation():
    def oof():
        return ootype.oostring(42, -1)

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


示例19: test_register_external_tuple_args

    def test_register_external_tuple_args(self):
        """
        Verify the annotation of a registered external function which takes a
        tuple argument.
        """

        def function_with_tuple_arg():
            """
            Dummy function which is declared via register_external to take a
            tuple as an argument so that register_external's behavior for
            tuple-taking functions can be verified.
            """

        register_external(function_with_tuple_arg, [(int,)], int)

        def f():
            return function_with_tuple_arg((1,))

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

        # Not a very good assertion, but at least it means _something_ happened.
        assert isinstance(s, annmodel.SomeInteger)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:25,代码来源:test_extfunc.py


示例20: test_ooparse_int

def test_ooparse_int():
    def oof(n, b):
        return ooparse_int(oostring(n, b), b)

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python bookkeeper.getbookkeeper函数代码示例发布时间:2022-05-27
下一篇:
Python utils.json_to_datetime函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap