本文整理汇总了Python中pypy.annotation.bookkeeper.getbookkeeper函数的典型用法代码示例。如果您正苦于以下问题:Python getbookkeeper函数的具体用法?Python getbookkeeper怎么用?Python getbookkeeper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getbookkeeper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mod
def mod((str, s_tuple)):
for s_item in s_tuple.items:
if isinstance(s_item, (SomeUnicodeCodePoint, SomeUnicodeString)):
raise NotImplementedError(
"string formatting mixing strings and unicode not supported")
getbookkeeper().count('strformat', str, s_tuple)
return SomeString()
示例2: getitem
def getitem((tup1, int2)):
if int2.is_immutable_constant():
try:
return tup1.items[int2.const]
except IndexError:
return s_ImpossibleValue
else:
getbookkeeper().count("tuple_random_getitem", tup1)
return unionof(*tup1.items)
示例3: method_join
def method_join(str, s_list):
if s_None.contains(s_list):
return SomeImpossibleValue()
getbookkeeper().count("str_join", str)
s_item = s_list.listdef.read_item()
if isinstance(s_item, SomeImpossibleValue):
if isinstance(str, SomeUnicodeString):
return immutablevalue(u"")
return immutablevalue("")
no_nul = str.no_nul and s_item.no_nul
return str.basestringclass(no_nul=no_nul)
示例4: builtin_isinstance
def builtin_isinstance(s_obj, s_type, variables=None):
r = SomeBool()
if s_type.is_constant():
typ = s_type.const
if issubclass(typ, pypy.rlib.rarithmetic.base_int):
r.const = issubclass(s_obj.knowntype, typ)
else:
if typ == long:
getbookkeeper().warning("isinstance(., long) is not RPython")
if s_obj.is_constant():
r.const = isinstance(s_obj.const, long)
else:
if type(s_obj) is not SomeObject: # only SomeObjects could be longs
# type(s_obj) < SomeObject -> SomeBool(False)
# type(s_obj) == SomeObject -> SomeBool()
r.const = False
return r
assert not issubclass(typ, (int, long)) or typ in (
bool,
int,
long,
), "for integers only isinstance(.,int|r_uint) are supported"
if s_obj.is_constant():
r.const = isinstance(s_obj.const, typ)
elif our_issubclass(s_obj.knowntype, typ):
if not s_obj.can_be_none():
r.const = True
elif not our_issubclass(typ, s_obj.knowntype):
r.const = False
elif s_obj.knowntype == int and typ == bool: # xxx this will explode in case of generalisation
# from bool to int, notice that isinstance( , bool|int)
# is quite border case for RPython
r.const = False
# XXX HACK HACK HACK
# XXX HACK HACK HACK
# XXX HACK HACK HACK
bk = getbookkeeper()
if variables is None:
fn, block, i = bk.position_key
op = block.operations[i]
assert op.opname == "simple_call"
assert len(op.args) == 3
assert op.args[0] == Constant(isinstance)
variables = [op.args[1]]
for variable in variables:
assert bk.annotator.binding(variable) == s_obj
r.knowntypedata = {}
if not isinstance(s_type, SomeBuiltin) or typ.__module__ == "__builtin__":
add_knowntypedata(r.knowntypedata, True, variables, bk.valueoftype(typ))
return r
示例5: builtin_hasattr
def builtin_hasattr(s_obj, s_attr):
if not s_attr.is_constant() or not isinstance(s_attr.const, str):
getbookkeeper().warning("hasattr(%r, %r) is not RPythonic enough" % (s_obj, s_attr))
r = SomeBool()
if s_obj.is_immutable_constant():
r.const = hasattr(s_obj.const, s_attr.const)
elif isinstance(s_obj, SomePBC) and s_obj.getKind() is description.FrozenDesc:
answers = {}
for d in s_obj.descriptions:
answer = d.s_read_attribute(s_attr.const) != s_ImpossibleValue
answers[answer] = True
if len(answers) == 1:
r.const, = answers
return r
示例6: mod
def mod((str, s_tuple)):
for s_item in s_tuple.items:
if isinstance(s_item, (SomeUnicodeCodePoint, SomeUnicodeString)):
raise NotImplementedError(
"string formatting mixing strings and unicode not supported")
getbookkeeper().count('strformat', str, s_tuple)
no_nul = str.no_nul
for s_item in s_tuple.items:
if isinstance(s_item, SomeFloat):
pass # or s_item is a subclass, like SomeInteger
elif isinstance(s_item, SomeString) and s_item.no_nul:
pass
else:
no_nul = False
break
return SomeString(no_nul=no_nul)
示例7: getbookkeeper
def getbookkeeper(self):
if self.bookkeeper is None:
from pypy.annotation.bookkeeper import getbookkeeper
return getbookkeeper()
else:
return self.bookkeeper
示例8: builtin_range
def builtin_range(*args):
s_step = immutablevalue(1)
if len(args) == 1:
s_start = immutablevalue(0)
s_stop = args[0]
elif len(args) == 2:
s_start, s_stop = args
elif len(args) == 3:
s_start, s_stop = args[:2]
s_step = args[2]
else:
raise Exception, "range() takes 1 to 3 arguments"
empty = False # so far
if not s_step.is_constant():
step = 0 # this case signals a variable step
else:
step = s_step.const
if step == 0:
raise Exception, "range() with step zero"
if s_start.is_constant() and s_stop.is_constant():
if len(xrange(s_start.const, s_stop.const, step)) == 0:
empty = True
if empty:
s_item = s_ImpossibleValue
else:
nonneg = False # so far
if step > 0:
nonneg = s_start.nonneg
elif step < 0:
nonneg = s_stop.nonneg or (s_stop.is_constant() and
s_stop.const >= -1)
s_item = SomeInteger(nonneg=nonneg)
return getbookkeeper().newlist(s_item, range_step=step)
示例9: getattr
def getattr(ins, s_attr):
if s_attr.is_constant() and isinstance(s_attr.const, str):
attr = s_attr.const
if attr == '__class__':
return ins.classdef.read_attr__class__()
attrdef = ins.classdef.find_attribute(attr)
position = getbookkeeper().position_key
attrdef.read_locations[position] = True
s_result = attrdef.getvalue()
# hack: if s_result is a set of methods, discard the ones
# that can't possibly apply to an instance of ins.classdef.
# XXX do it more nicely
if isinstance(s_result, SomePBC):
s_result = ins.classdef.lookup_filter(s_result, attr,
ins.flags)
elif isinstance(s_result, SomeImpossibleValue):
ins.classdef.check_missing_attribute_update(attr)
# blocking is harmless if the attribute is explicitly listed
# in the class or a parent class.
for basedef in ins.classdef.getmro():
if basedef.classdesc.all_enforced_attrs is not None:
if attr in basedef.classdesc.all_enforced_attrs:
raise HarmlesslyBlocked("get enforced attr")
elif isinstance(s_result, SomeList):
s_result = ins.classdef.classdesc.maybe_return_immutable_list(
attr, s_result)
return s_result
return SomeObject()
示例10: compute_result_annotation
def compute_result_annotation(self, s_rpytype, s_obj):
from pypy.annotation.bookkeeper import getbookkeeper
from pypy.annotation.model import SomeInstance
assert s_rpytype.is_constant()
rpytype = s_rpytype.const
bk = getbookkeeper()
return SomeInstance(bk.getuniqueclassdef(rpytype))
示例11: our_issubclass
def our_issubclass(cls1, cls2):
""" we're going to try to be less silly in the face of old-style classes"""
from pypy.annotation.classdef import ClassDef
if cls2 is object:
return True
def classify(cls):
if isinstance(cls, ClassDef):
return 'def'
if cls.__module__ == '__builtin__':
return 'builtin'
else:
return 'cls'
kind1 = classify(cls1)
kind2 = classify(cls2)
if kind1 != 'def' and kind2 != 'def':
return issubclass(cls1, cls2)
if kind1 == 'builtin' and kind2 == 'def':
return False
elif kind1 == 'def' and kind2 == 'builtin':
return issubclass(object, cls2)
else:
bk = getbookkeeper()
def toclassdef(kind, cls):
if kind != 'def':
return bk.getuniqueclassdef(cls)
else:
return cls
return toclassdef(kind1, cls1).issubclass(toclassdef(kind2, cls2))
示例12: unioncheck
def unioncheck(*somevalues):
s_value = unionof(*somevalues)
if isdegenerated(s_value):
if not getattr(TLS, 'no_side_effects_in_union', 0):
bookkeeper = getbookkeeper()
if bookkeeper is not None:
bookkeeper.ondegenerated('union', s_value)
return s_value
示例13: robjmodel_r_dict
def robjmodel_r_dict(s_eqfn, s_hashfn, s_force_non_null=None):
if s_force_non_null is None:
force_non_null = False
else:
assert s_force_non_null.is_constant()
force_non_null = s_force_non_null.const
dictdef = getbookkeeper().getdictdef(is_r_dict=True, force_non_null=force_non_null)
dictdef.dictkey.update_rdict_annotations(s_eqfn, s_hashfn)
return SomeDict(dictdef)
示例14: read_key
def read_key(self, position_key=None):
if position_key is None:
if self.bookkeeper is None: # for tests
from pypy.annotation.bookkeeper import getbookkeeper
position_key = getbookkeeper().position_key
else:
position_key = self.bookkeeper.position_key
self.dictkey.read_locations[position_key] = True
return self.dictkey.s_value
示例15: record_call
def record_call(func, args_s, symbol):
from pypy.annotation import bookkeeper
bk = bookkeeper.getbookkeeper()
# this would be nice!
#bk.pbc_call(bk.immutablevalue(func),
# bk.build_args("simple_call", args_s),
# emulated=True)
bk.annotator.translator._implicitly_called_by_externals.append(
(func, args_s, symbol))