本文整理汇总了Python中pypy.annotation.model.SomeObject类的典型用法代码示例。如果您正苦于以下问题:Python SomeObject类的具体用法?Python SomeObject怎么用?Python SomeObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SomeObject类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: union
def union((obj1, obj2)):
if obj1 == obj2:
return obj1
else:
result = SomeObject()
if obj1.knowntype == obj2.knowntype and obj1.knowntype != object:
result.knowntype = obj1.knowntype
is_type_of1 = getattr(obj1, 'is_type_of', None)
is_type_of2 = getattr(obj2, 'is_type_of', None)
if obj1.is_immutable_constant() and obj2.is_immutable_constant() and obj1.const == obj2.const:
result.const = obj1.const
is_type_of = {}
if is_type_of1:
for v in is_type_of1:
is_type_of[v] = True
if is_type_of2:
for v in is_type_of2:
is_type_of[v] = True
if is_type_of:
result.is_type_of = is_type_of.keys()
else:
if is_type_of1 and is_type_of1 == is_type_of2:
result.is_type_of = is_type_of1
# try to preserve the origin of SomeObjects
if obj1 == result:
result = obj1
elif obj2 == result:
result = obj2
unioncheck(result)
return result
示例2: newtuple
def newtuple(self, items_s):
if len(items_s) == 1 and items_s[0] is Ellipsis:
res = SomeObject() # hack to get a SomeObject as the *arg
res.from_ellipsis = True
return res
else:
return SomeTuple(items_s)
示例3: annotationoftype
def annotationoftype(t, bookkeeper=False):
from pypy.rpython import extregistry
"""The most precise SomeValue instance that contains all
objects of type t."""
assert isinstance(t, (type, types.ClassType))
if t is bool:
return SomeBool()
elif t is int:
return SomeInteger()
elif t is float:
return SomeFloat()
elif issubclass(t, str): # py.lib uses annotated str subclasses
return SomeString()
elif t is unicode:
return SomeUnicodeString()
elif t is list:
return SomeList(MOST_GENERAL_LISTDEF)
elif t is dict:
return SomeDict(MOST_GENERAL_DICTDEF)
# can't do tuple
elif t is types.NoneType:
return s_None
elif bookkeeper and extregistry.is_registered_type(t, bookkeeper.policy):
entry = extregistry.lookup_type(t, bookkeeper.policy)
return entry.compute_annotation_bk(bookkeeper)
elif bookkeeper and t.__module__ != '__builtin__' and t not in bookkeeper.pbctypes:
classdef = bookkeeper.getuniqueclassdef(t)
return SomeInstance(classdef)
else:
o = SomeObject()
if t != object:
o.knowntype = t
return o
示例4: newtuple
def newtuple(self, items_s):
if items_s == [Ellipsis]:
res = SomeObject() # hack to get a SomeObject as the *arg
res.from_ellipsis = True
return res
else:
return SomeTuple(items_s)
示例5: find_method
def find_method(obj, name):
"Look for a special-case implementation for the named method."
type_analyser = builtin.EXTERNAL_TYPE_ANALYZERS[obj.knowntype]
if name in type_analyser:
analyser = type_analyser[name]
return SomeBuiltin(analyser, obj, name)
return SomeObject.find_method(obj, name)
示例6: simple_call
def simple_call(self, *s_args):
from pypy.translator.cli.query import get_cli_class
DELEGATE = get_cli_class('System.Delegate')._INSTANCE
if ootype.isSubclass(self.ootype, DELEGATE):
s_invoke = self.getattr(immutablevalue('Invoke'))
return s_invoke.simple_call(*s_args)
else:
# cannot call a non-delegate
return SomeObject.simple_call(self, *s_args)
示例7: compute_result_annotation
def compute_result_annotation(self, s_obj):
if s_None.contains(s_obj):
return s_obj
assert isinstance(s_obj, (SomeString, SomeUnicodeString))
if s_obj.no_nul:
return s_obj
new_s_obj = SomeObject.__new__(s_obj.__class__)
new_s_obj.__dict__ = s_obj.__dict__.copy()
new_s_obj.no_nul = True
return new_s_obj
示例8: getattr
def getattr(p, s_attr):
if s_attr.is_constant() and isinstance(s_attr.const, str):
# XXX kill with extfunctable.py
if p.knowntype in builtin.EXTERNAL_TYPE_ANALYZERS:
return SomeObject.getattr(p, s_attr)
attr = s_attr.const
entry = extregistry.lookup_type(p.knowntype)
s_value = entry.get_field_annotation(p.knowntype, attr)
return s_value
else:
return SomeObject()
示例9: getattr
def getattr(s_array, s_attr):
s = None
if s_attr.is_constant() and isinstance(s_attr.const, str):
attr = s_attr.const
if attr == 'shape':
s = SomeTuple([SomeInteger()]*s_array.ndim)
elif attr == 'ndim':
s = SomeInteger()
elif attr == 'dtype':
s = SomeChar()
if s is None:
return SomeObject.getattr(s_array, s_attr)
return s
示例10: len
def len(p):
length = p.ll_ptrtype._example()._fixedlength()
if length is None:
return SomeObject.len(p)
else:
return immutablevalue(length)
示例11: len
def len(dct):
s_key = dct.dictdef.read_key()
s_value = dct.dictdef.read_value()
if isinstance(s_key, SomeImpossibleValue) or isinstance(s_value, SomeImpossibleValue):
return immutablevalue(0)
return SomeObject.len(dct)