本文整理汇总了Python中pypy.annotation.model.SomeBool.knowntype方法的典型用法代码示例。如果您正苦于以下问题:Python SomeBool.knowntype方法的具体用法?Python SomeBool.knowntype怎么用?Python SomeBool.knowntype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.annotation.model.SomeBool
的用法示例。
在下文中一共展示了SomeBool.knowntype方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: immutablevalue
# 需要导入模块: from pypy.annotation.model import SomeBool [as 别名]
# 或者: from pypy.annotation.model.SomeBool import knowntype [as 别名]
#.........这里部分代码省略.........
if tp is r_dict:
s_eqfn = self.immutablevalue(x.key_eq)
s_hashfn = self.immutablevalue(x.key_hash)
result.dictdef.dictkey.update_rdict_annotations(s_eqfn,
s_hashfn)
seen_elements = 0
while seen_elements != len(x):
items = x.items()
for ek, ev in items:
result.dictdef.generalize_key(self.immutablevalue(ek))
result.dictdef.generalize_value(self.immutablevalue(ev))
result.dictdef.seen_prebuilt_key(ek)
seen_elements = len(items)
# if the dictionary grew during the iteration,
# start over again
result.const_box = key
return result
else:
dictdef = DictDef(self,
s_ImpossibleValue,
s_ImpossibleValue,
is_r_dict = tp is r_dict)
if tp is r_dict:
s_eqfn = self.immutablevalue(x.key_eq)
s_hashfn = self.immutablevalue(x.key_hash)
dictdef.dictkey.update_rdict_annotations(s_eqfn,
s_hashfn)
for ek, ev in x.iteritems():
dictdef.generalize_key(self.immutablevalue(ek, False))
dictdef.generalize_value(self.immutablevalue(ev, False))
dictdef.seen_prebuilt_key(ek)
result = SomeDict(dictdef)
elif tp is weakref.ReferenceType:
x1 = x()
if x1 is None:
result = SomeWeakRef(None) # dead weakref
else:
s1 = self.immutablevalue(x1)
assert isinstance(s1, SomeInstance)
result = SomeWeakRef(s1.classdef)
elif ishashable(x) and x in BUILTIN_ANALYZERS:
_module = getattr(x,"__module__","unknown")
result = SomeBuiltin(BUILTIN_ANALYZERS[x], methodname="%s.%s" % (_module, x.__name__))
elif extregistry.is_registered(x, self.policy):
entry = extregistry.lookup(x, self.policy)
result = entry.compute_annotation_bk(self)
elif isinstance(x, lltype._ptr):
result = SomePtr(lltype.typeOf(x))
elif isinstance(x, llmemory.fakeaddress):
result = SomeAddress()
elif isinstance(x, ootype._static_meth):
result = SomeOOStaticMeth(ootype.typeOf(x))
elif isinstance(x, ootype._class):
result = SomeOOClass(x._INSTANCE) # NB. can be None
elif isinstance(x, ootype.instance_impl): # XXX
result = SomeOOInstance(ootype.typeOf(x))
elif isinstance(x, (ootype._record, ootype._string)):
result = SomeOOInstance(ootype.typeOf(x))
elif isinstance(x, (ootype._object)):
result = SomeOOObject()
elif callable(x):
if hasattr(x, 'im_self') and hasattr(x, 'im_func'):
# on top of PyPy, for cases like 'l.append' where 'l' is a
# global constant list, the find_method() returns non-None
s_self = self.immutablevalue(x.im_self, need_const)
result = s_self.find_method(x.im_func.__name__)
elif hasattr(x, '__self__') and x.__self__ is not None:
# for cases like 'l.append' where 'l' is a global constant list
s_self = self.immutablevalue(x.__self__, need_const)
result = s_self.find_method(x.__name__)
if result is None:
result = SomeObject()
else:
result = None
if result is None:
if (self.annotator.policy.allow_someobjects
and getattr(x, '__module__', None) == '__builtin__'
# XXX note that the print support functions are __builtin__
and tp not in (types.FunctionType, types.MethodType)):
result = SomeObject()
result.knowntype = tp # at least for types this needs to be correct
else:
result = SomePBC([self.getdesc(x)])
elif hasattr(x, '_freeze_') and x._freeze_():
# user-defined classes can define a method _freeze_(), which
# is called when a prebuilt instance is found. If the method
# returns True, the instance is considered immutable and becomes
# a SomePBC(). Otherwise it's just SomeInstance().
result = SomePBC([self.getdesc(x)])
elif hasattr(x, '__class__') \
and x.__class__.__module__ != '__builtin__':
self.see_mutable(x)
result = SomeInstance(self.getuniqueclassdef(x.__class__))
elif x is None:
return s_None
else:
result = SomeObject()
if need_const:
result.const = x
return result