本文整理汇总了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)
示例2: test_annotate_1
def test_annotate_1():
def f():
return eraseX(X())
a = RPythonAnnotator()
s = a.build_types(f, [])
assert isinstance(s, SomeErased)
示例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)
示例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
示例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
示例6: test_new_bltn
def test_new_bltn():
def new():
return C()
a = RPythonAnnotator()
s = a.build_types(new, [])
assert s.knowntype is C
示例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
示例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)
示例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
示例10: test_string
def test_string():
def oof():
return new(String)
a = RPythonAnnotator()
s = a.build_types(oof, [])
assert s == annmodel.SomeOOInstance(String)
示例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
示例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)
示例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
示例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
示例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