本文整理汇总了Python中pypy.tool.pairtype.pair函数的典型用法代码示例。如果您正苦于以下问题:Python pair函数的具体用法?Python pair怎么用?Python pair使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pair函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_somebuiltin
def test_somebuiltin():
### Operation on built-in types
class MiniPickler:
def __init__(self):
self.data = []
def emit(self, datum):
self.data.append(datum)
class __extend__(pairtype(MiniPickler, int)):
def write((pickler, x)):
pickler.emit('I%d' % x)
class __extend__(pairtype(MiniPickler, str)):
def write((pickler, x)):
pickler.emit('S%s' % x)
class __extend__(pairtype(MiniPickler, list)):
def write((pickler, x)):
for item in x:
pair(pickler, item).write()
pickler.emit('L%d' % len(x))
p = MiniPickler()
pair(p, [1, 2, ['hello', 3]]).write()
assert p.data == ['I1', 'I2', 'Shello', 'I3', 'L2', 'L3']
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:test_pairtype.py
示例2: setinteriorfield
def setinteriorfield(hs_v1, *offsets_and_val_hs):
hs_inner = hs_v1._getinterior(*offsets_and_val_hs[:-2])
hs_lastofs = offsets_and_val_hs[-2]
hs_value = offsets_and_val_hs[-1]
if hs_lastofs.concretetype is lltype.Signed:
pair(hs_inner, hs_lastofs).setarrayitem(hs_value)
else:
hs_inner.setfield(hs_lastofs, hs_value)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:model.py
示例3: get_loader
def get_loader(type):
s_obj = annotation(type, None)
try:
# look for a marshaller in the 'loaders' list
return find_loader(s_obj)
except CannotUnmarshall:
# ask the annotation to produce an appropriate loader
pair(_tag, s_obj).install_unmarshaller()
return find_loader(s_obj)
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:rmarshal.py
示例4: get_marshaller
def get_marshaller(type):
"""Return a marshaller function.
The marshaller takes two arguments: a buffer and an object of
type 'type'. The buffer is list of characters that gets extended
with new data when the marshaller is called.
"""
s_obj = annotation(type, None)
try:
# look for a marshaller in the 'dumpers' list
return find_dumper(s_obj)
except CannotMarshal:
# ask the annotation to produce an appropriate dumper
pair(_tag, s_obj).install_marshaller()
return find_dumper(s_obj)
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:rmarshal.py
示例5: improve
def improve((ins1, ins2)):
if ins1.classdef is None:
resdef = ins2.classdef
elif ins2.classdef is None:
resdef = ins1.classdef
else:
basedef = ins1.classdef.commonbase(ins2.classdef)
if basedef is ins1.classdef:
resdef = ins2.classdef
elif basedef is ins2.classdef:
resdef = ins1.classdef
else:
if ins1.can_be_None and ins2.can_be_None:
return s_None
else:
return s_ImpossibleValue
res = SomeInstance(
resdef, can_be_None=ins1.can_be_None and ins2.can_be_None)
if ins1.contains(res) and ins2.contains(res):
return res # fine
else:
# this case can occur in the presence of 'const' attributes,
# which we should try to preserve. Fall-back...
thistype = pairtype(SomeInstance, SomeInstance)
return super(thistype, pair(ins1, ins2)).improve()
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:25,代码来源:binaryop.py
示例6: getinteriorfield
def getinteriorfield(hs_v1, *offsets_hs):
hs_container = hs_v1._getinterior(*offsets_hs[:-1])
hs_lastofs = offsets_hs[-1]
if hs_lastofs.concretetype is lltype.Signed:
return pair(hs_container, hs_lastofs).getarrayitem()
else:
return hs_container.getfield(hs_lastofs)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:model.py
示例7: union
def union((hs_v1, hs_v2)):
if hs_v1.deepfrozen != hs_v2.deepfrozen:
hs_v1 = deepunfreeze(hs_v1)
hs_v2 = deepunfreeze(hs_v2)
if hs_v1 == hs_v2:
return hs_v1
return pair(hs_v1, hs_v2).union_frozen_equal()
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:model.py
示例8: unionof
def unionof(*somevalues):
"The most precise SomeValue instance that contains all the values."
try:
s1, s2 = somevalues
except ValueError:
s1 = s_ImpossibleValue
for s2 in somevalues:
if s1 != s2:
s1 = pair(s1, s2).union()
else:
# this is just a performance shortcut
if s1 != s2:
s1 = pair(s1, s2).union()
if DEBUG:
if s1.caused_by_merge is None and len(somevalues) > 1:
s1.caused_by_merge = somevalues
return s1
开发者ID:gorakhargosh,项目名称:pypy,代码行数:17,代码来源:model.py
示例9: _getinterior
def _getinterior(hs_v1, *offsets_hs):
hs_container = hs_v1
for hs_offset in offsets_hs:
if hs_offset.concretetype is lltype.Signed:
hs_container = pair(hs_container,hs_offset).getarraysubstruct()
else:
hs_container = hs_container.getsubstruct(hs_offset)
return hs_container
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:model.py
示例10: getitem
def getitem((s_array, s_index)):
ndim = pair(s_array, s_index).get_leftover_dim()
if len(s_index.items)>s_array.ndim:
raise AnnotatorError("invalid index")
if s_array.ndim == 0 and len(s_index.items):
raise AnnotatorError("indexing rank zero array with nonempty tuple")
if ndim > 0:
return SomeArray(s_array.typecode, ndim)
return s_array.get_item_type()
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:aarray.py
示例11: is_
def is_((pbc1, pbc2)):
thistype = pairtype(SomePBC, SomePBC)
s = super(thistype, pair(pbc1, pbc2)).is_()
if not s.is_constant():
if not pbc1.can_be_None or not pbc2.can_be_None:
for desc in pbc1.descriptions:
if desc in pbc2.descriptions:
break
else:
s.const = False # no common desc in the two sets
return s
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:binaryop.py
示例12: convertvar
def convertvar(self, v, r_from, r_to):
assert isinstance(v, (Variable, Constant))
if r_from != r_to:
v = pair(r_from, r_to).convert_from_to(v, self)
if v is NotImplemented:
raise TyperError("don't know how to convert from %r to %r" %
(r_from, r_to))
if v.concretetype != r_to.lowleveltype:
raise TyperError("bug in conversion from %r to %r: "
"returned a %r" % (r_from, r_to,
v.concretetype))
return v
开发者ID:ieure,项目名称:pypy,代码行数:12,代码来源:rtyper.py
示例13: contains
def contains(self, other):
if self == other:
return True
try:
TLS.no_side_effects_in_union += 1
except AttributeError:
TLS.no_side_effects_in_union = 1
try:
try:
return pair(self, other).union() == self
except UnionError:
return False
finally:
TLS.no_side_effects_in_union -= 1
开发者ID:gorakhargosh,项目名称:pypy,代码行数:14,代码来源:model.py
示例14: test_binop
def test_binop():
### Binary operation example
class __extend__(pairtype(int, int)):
def add((x, y)):
return 'integer: %s+%s' % (x, y)
def sub((x, y)):
return 'integer: %s-%s' % (x, y)
class __extend__(pairtype(bool, bool)):
def add((x, y)):
return 'bool: %s+%s' % (x, y)
assert pair(3,4).add() == 'integer: 3+4'
assert pair(3,4).sub() == 'integer: 3-4'
assert pair(3,True).add() == 'integer: 3+True'
assert pair(3,True).sub() == 'integer: 3-True'
assert pair(False,4).add() == 'integer: False+4'
assert pair(False,4).sub() == 'integer: False-4'
assert pair(False,True).add() == 'bool: False+True'
assert pair(False,True).sub() == 'integer: False-True'
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:20,代码来源:test_pairtype.py
示例15: inplace_add
def inplace_add((obj1, obj2)): return pair(obj1, obj2).add()
def inplace_sub((obj1, obj2)): return pair(obj1, obj2).sub()
开发者ID:alkorzt,项目名称:pypy,代码行数:2,代码来源:binaryop.py
示例16: union
def union((obj, r2)):
return pair(r2, obj).union()
开发者ID:alkorzt,项目名称:pypy,代码行数:2,代码来源:binaryop.py
示例17: inplace_truediv
def inplace_truediv((obj1, obj2)): return pair(obj1, obj2).truediv()
def inplace_floordiv((obj1, obj2)): return pair(obj1, obj2).floordiv()
开发者ID:alkorzt,项目名称:pypy,代码行数:2,代码来源:binaryop.py
示例18: coerce
def coerce((obj1, obj2)):
getbookkeeper().count("coerce", obj1, obj2)
return pair(obj1, obj2).union() # reasonable enough
开发者ID:alkorzt,项目名称:pypy,代码行数:3,代码来源:binaryop.py
示例19: inplace_or
def inplace_or((obj1, obj2)): return pair(obj1, obj2).or_()
def inplace_xor((obj1, obj2)): return pair(obj1, obj2).xor()
开发者ID:alkorzt,项目名称:pypy,代码行数:2,代码来源:binaryop.py
示例20: inplace_and
def inplace_and((obj1, obj2)): return pair(obj1, obj2).and_()
def inplace_or((obj1, obj2)): return pair(obj1, obj2).or_()
开发者ID:alkorzt,项目名称:pypy,代码行数:2,代码来源:binaryop.py
注:本文中的pypy.tool.pairtype.pair函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论