本文整理汇总了Python中pypy.annotation.annrpython.RPythonAnnotator.build_types方法的典型用法代码示例。如果您正苦于以下问题:Python RPythonAnnotator.build_types方法的具体用法?Python RPythonAnnotator.build_types怎么用?Python RPythonAnnotator.build_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.annotation.annrpython.RPythonAnnotator
的用法示例。
在下文中一共展示了RPythonAnnotator.build_types方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_annotate
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
def test_annotate():
for inttype in inttypes:
c = inttype()
def f():
return c
a = RPythonAnnotator()
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeInteger)
assert s.knowntype == inttype
assert s.unsigned == (inttype(-1) > 0)
for inttype in inttypes:
def f():
return inttype(0)
a = RPythonAnnotator()
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeInteger)
assert s.knowntype == inttype
assert s.unsigned == (inttype(-1) > 0)
for inttype in inttypes:
def f(x):
return x
a = RPythonAnnotator()
s = a.build_types(f, [inttype])
assert isinstance(s, annmodel.SomeInteger)
assert s.knowntype == inttype
assert s.unsigned == (inttype(-1) > 0)
示例2: test_union
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
def test_union(self):
def f(x, y):
if y:
addr = NULL
else:
if x:
addr = NULL
else:
addr = raw_malloc(10)
return addr
a = RPythonAnnotator()
s_true = annmodel.SomeBool()
s_true.const = True
s_false = annmodel.SomeBool()
s_false.const = False
s = a.build_types(f, [bool, bool])
assert isinstance(s, annmodel.SomeAddress)
assert not s.is_null
a = RPythonAnnotator()
s = a.build_types(f, [s_true, bool])
assert isinstance(s, annmodel.SomeAddress)
assert s.is_null
assert f(True, False) == NULL
a = RPythonAnnotator()
s = a.build_types(f, [s_false, bool])
assert isinstance(s, annmodel.SomeAddress)
assert not s.is_null
示例3: test_overloaded_meth
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
def test_overloaded_meth():
C = Instance("test", ROOT, {},
{'foo': overload(meth(Meth([Float], Void)),
meth(Meth([Signed], Signed)),
meth(Meth([], Float)))})
def fn1():
return new(C).foo(42.5)
def fn2():
return new(C).foo(42)
def fn3():
return new(C).foo()
a = RPythonAnnotator()
assert a.build_types(fn1, []) is annmodel.s_None
assert isinstance(a.build_types(fn2, []), annmodel.SomeInteger)
assert isinstance(a.build_types(fn3, []), annmodel.SomeFloat)
示例4: test_annotate_wrapping
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
def test_annotate_wrapping(self):
def wrap(x):
return py_object(x)
a = RPythonAnnotator()
s = a.build_types(wrap, [int])
assert s.knowntype == py_object
if conftest.option.view:
a.translator.view()
a = RPythonAnnotator()
s = a.build_types(wrap, [str])
assert s.knowntype == py_object
if conftest.option.view:
a.translator.view()
示例5: test_annotate_prebuilt_int
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
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)
示例6: test_callback
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [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)
示例7: test_class
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
def test_class(self):
def fn():
return Math
a = RPythonAnnotator()
s = a.build_types(fn, [])
assert isinstance(s, SomeCliClass)
assert s.const is Math
示例8: test_register_external_tuple_args
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [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)
示例9: test_string
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
def test_string():
def oof():
return new(String)
a = RPythonAnnotator()
s = a.build_types(oof, [])
assert s == annmodel.SomeOOInstance(String)
示例10: test_ooparse_int
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
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)
示例11: test_unbox
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
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)
示例12: test_oostring_annotation
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
def test_oostring_annotation():
def oof():
return ootype.oostring
a = RPythonAnnotator()
s = a.build_types(oof, [])
assert isinstance(s, annmodel.SomeBuiltin)
示例13: test_annotate_1
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
def test_annotate_1():
def f():
return eraseX(X())
a = RPythonAnnotator()
s = a.build_types(f, [])
assert isinstance(s, SomeErased)
示例14: test_annotate_erasing_pair
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
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)
示例15: test_isinstance
# 需要导入模块: from pypy.annotation.annrpython import RPythonAnnotator [as 别名]
# 或者: from pypy.annotation.annrpython.RPythonAnnotator import build_types [as 别名]
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