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


Python AnnotatorPolicy.allow_someobjects方法代码示例

本文整理汇总了Python中pypy.annotation.policy.AnnotatorPolicy.allow_someobjects方法的典型用法代码示例。如果您正苦于以下问题:Python AnnotatorPolicy.allow_someobjects方法的具体用法?Python AnnotatorPolicy.allow_someobjects怎么用?Python AnnotatorPolicy.allow_someobjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pypy.annotation.policy.AnnotatorPolicy的用法示例。


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

示例1: test_register_external_tuple_args

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
    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,代码行数:27,代码来源:test_extfunc.py

示例2: test_register_external_return_goes_back

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
    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,代码行数:27,代码来源:test_extfunc.py

示例3: test_callback

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
    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,代码行数:28,代码来源:test_extfunc.py

示例4: test_basic

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
    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,代码行数:29,代码来源:test_extfunc.py

示例5: __init__

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
    def __init__(self, function, annotations, stackless=False, view=False, html=None, is_interactive=False, root = None, run_browser = True, policy = None):
        if not use_browsertest and not _CLI_is_on_path():
            py.test.skip('Javascript CLI (js) not found')

        self.html = html
        self.is_interactive = is_interactive
        t = TranslationContext()
        
        if policy is None:
            from pypy.annotation.policy import AnnotatorPolicy
            policy = AnnotatorPolicy()
            policy.allow_someobjects = False

        ann = t.buildannotator(policy=policy)
        ann.build_types(function, annotations)
        if view or option.view:
            t.view()
        t.buildrtyper(type_system="ootype").specialize()

        if view or option.view:
            t.view()
        #self.js = JS(t, [function, callback_function], stackless)
        self.js = JS(t, function, stackless)
        self.js.write_source()
        if root is None and use_tg:
            from pypy.translator.js.demo.jsdemo.controllers import Root
            self.root = Root
        else:
            self.root = root
        self.run_browser = run_browser
        self.function_calls = []
开发者ID:antoine1fr,项目名称:pygirl,代码行数:33,代码来源:runtest.py

示例6: get_interpreter

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
def get_interpreter(func, values, view='auto', viewbefore='auto', policy=None,
                    someobjects=False, type_system="lltype", backendopt=False, config=None):
    key = (func,) + tuple([typeOf(x) for x in values])+ (someobjects,
                                                         backendopt)
    try: 
        (t, interp, graph) = _tcache[key]
    except KeyError:
        def annotation(x):
            T = typeOf(x)
            if T == Ptr(PyObject) and someobjects:
                return object
            elif T == Ptr(rstr.STR):
                return str
            else:
                return lltype_to_annotation(T)

        if policy is None and not someobjects:
            from pypy.annotation.policy import AnnotatorPolicy
            policy = AnnotatorPolicy()
            policy.allow_someobjects = False

        t, typer, graph = gengraph(func, [annotation(x) for x in values],
                                   viewbefore, policy, type_system=type_system,
                                   backendopt=backendopt, config=config)
        interp = LLInterpreter(typer)
        _tcache[key] = (t, interp, graph)
        # keep the cache small 
        _lastinterpreted.append(key) 
        if len(_lastinterpreted) >= 4: 
            del _tcache[_lastinterpreted.pop(0)]
    if view == 'auto':
        view = conftest.option.view
    if view:
        t.view()
    return interp, graph
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:37,代码来源:test_llinterp.py

示例7: test_register_external_signature

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
def test_register_external_signature():
    def f():
        return dd(3)

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

示例8: test_annotation_b

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
def test_annotation_b():
    def f():
        return b(1)
    
    policy = AnnotatorPolicy()
    policy.allow_someobjects = False
    a = RPythonAnnotator(policy=policy)
    s = a.build_types(f, [])
    assert isinstance(s, annmodel.SomeInteger)
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:test_extfunc.py

示例9: test_register_external_specialcase

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
def test_register_external_specialcase():
    def f():
        x = function_withspecialcase
        return x(33) + x("aaa") + x([]) + "\n"

    policy = AnnotatorPolicy()
    policy.allow_someobjects = False
    a = RPythonAnnotator(policy=policy)
    s = a.build_types(f, [])
    assert isinstance(s, annmodel.SomeString)
开发者ID:alkorzt,项目名称:pypy,代码行数:12,代码来源:test_extfunc.py

示例10: get_interpreter

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
def get_interpreter(
    func,
    values,
    view="auto",
    viewbefore="auto",
    policy=None,
    someobjects=False,
    type_system="lltype",
    backendopt=False,
    config=None,
    **extraconfigopts
):
    extra_key = [(key, value) for key, value in extraconfigopts.iteritems()]
    extra_key.sort()
    extra_key = tuple(extra_key)
    key = (func,) + tuple([typeOf(x) for x in values]) + (someobjects, backendopt, extra_key)
    try:
        (t, interp, graph) = _tcache[key]
    except KeyError:

        def annotation(x):
            T = typeOf(x)
            if T == Ptr(PyObject) and someobjects:
                return object
            else:
                return lltype_to_annotation(T)

        if policy is None and not someobjects:
            from pypy.annotation.policy import AnnotatorPolicy

            policy = AnnotatorPolicy()
            policy.allow_someobjects = False

        t, typer, graph = gengraph(
            func,
            [annotation(x) for x in values],
            viewbefore,
            policy,
            type_system=type_system,
            backendopt=backendopt,
            config=config,
            **extraconfigopts
        )
        interp = LLInterpreter(typer)
        _tcache[key] = (t, interp, graph)
        # keep the cache small
        _lastinterpreted.append(key)
        if len(_lastinterpreted) >= 4:
            del _tcache[_lastinterpreted.pop(0)]
    if view == "auto":
        view = getattr(conftest.option, "view", False)
    if view:
        t.view()
    return interp, graph
开发者ID:are-prabhu,项目名称:pypy,代码行数:56,代码来源:test_llinterp.py

示例11: test_callback

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
def test_callback():
    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:alkorzt,项目名称:pypy,代码行数:15,代码来源:test_extfunc.py

示例12: test_register_external_tuple_args

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
def test_register_external_tuple_args():
    """
    Verify the annotation of a registered external function which takes a tuple
    argument.
    """
    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:alkorzt,项目名称:pypy,代码行数:17,代码来源:test_extfunc.py

示例13: test_register_external_signature

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
    def test_register_external_signature(self):
        """
        Test the standard interface for external functions.
        """
        def dd():
            pass
        register_external(dd, [int], int)

        def f():
            return dd(3)

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

示例14: test_register_external_specialcase

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
    def test_register_external_specialcase(self):
        """
        When args=None, the external function accepts any arguments unmodified.
        """
        def function_withspecialcase(arg):
            return repr(arg)
        register_external(function_withspecialcase, args=None, result=str)

        def f():
            x = function_withspecialcase
            return x(33) + x("aaa") + x([]) + "\n"

        policy = AnnotatorPolicy()
        policy.allow_someobjects = False
        a = RPythonAnnotator(policy=policy)
        s = a.build_types(f, [])
        assert isinstance(s, annmodel.SomeString)
开发者ID:ieure,项目名称:pypy,代码行数:19,代码来源:test_extfunc.py

示例15: test_prebuilt_lock

# 需要导入模块: from pypy.annotation.policy import AnnotatorPolicy [as 别名]
# 或者: from pypy.annotation.policy.AnnotatorPolicy import allow_someobjects [as 别名]
def test_prebuilt_lock():
    import thread
    import pypy.module.thread.rpython.exttable   # for declare()/declaretype()
    lock0 = thread.allocate_lock()
    lock1 = thread.allocate_lock()
    lock1.acquire()
    def fn(i):
        lock = [lock0, lock1][i]
        ok = lock.acquire(False)
        if ok: lock.release()
        return ok
    policy = AnnotatorPolicy()
    policy.allow_someobjects = False
    res = interpret(fn, [0], policy=policy)
    assert res is True
    res = interpret(fn, [1], policy=policy)
    assert res is False
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:19,代码来源:test_rexternalobj.py


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