本文整理汇总了Python中pypy.interpreter.baseobjspace.ObjSpace.unpackiterable方法的典型用法代码示例。如果您正苦于以下问题:Python ObjSpace.unpackiterable方法的具体用法?Python ObjSpace.unpackiterable怎么用?Python ObjSpace.unpackiterable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.interpreter.baseobjspace.ObjSpace
的用法示例。
在下文中一共展示了ObjSpace.unpackiterable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: listview
# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
def listview(self, w_obj, expected_length=-1):
t = self.listview_no_unpack(w_obj)
if t is None:
return ObjSpace.unpackiterable(self, w_obj, expected_length)
if expected_length != -1 and len(t) != expected_length:
raise self._wrap_expected_length(expected_length, len(t))
return t
示例2: unpackiterable
# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
def unpackiterable(self, w_obj, expected_length=-1):
if isinstance(w_obj, W_AbstractTupleObject) and self._uses_tuple_iter(w_obj):
t = w_obj.getitems_copy()
elif type(w_obj) is W_ListObject:
t = w_obj.getitems_copy()
else:
return ObjSpace.unpackiterable(self, w_obj, expected_length)
if expected_length != -1 and len(t) != expected_length:
raise self._wrap_expected_length(expected_length, len(t))
return t
示例3: listview
# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
def listview(self, w_obj, expected_length=-1):
if isinstance(w_obj, W_ListObject):
t = w_obj.wrappeditems
elif isinstance(w_obj, W_TupleObject):
t = w_obj.wrappeditems[:]
else:
return ObjSpace.unpackiterable(self, w_obj, expected_length)
if expected_length != -1 and len(t) != expected_length:
raise self._wrap_expected_length(expected_length, len(t))
return t
示例4: fixedview
# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
def fixedview(self, w_obj, expected_length=-1, unroll=False):
""" Fast paths
"""
if isinstance(w_obj, W_TupleObject):
t = w_obj.wrappeditems
elif isinstance(w_obj, W_ListObject):
t = w_obj.wrappeditems[:]
else:
if unroll:
return make_sure_not_resized(ObjSpace.unpackiterable_unroll(
self, w_obj, expected_length)[:])
else:
return make_sure_not_resized(ObjSpace.unpackiterable(
self, w_obj, expected_length)[:])
if expected_length != -1 and len(t) != expected_length:
raise self._wrap_expected_length(expected_length, len(t))
return make_sure_not_resized(t)
示例5: unpackiterable
# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
def unpackiterable(self, w_iterable, expected_length=None):
if not isinstance(w_iterable, Variable):
l = list(self.unwrap(w_iterable))
if expected_length is not None and len(l) != expected_length:
raise ValueError
return [self.wrap(x) for x in l]
if isinstance(w_iterable, Variable) and expected_length is None:
raise UnwrapException, ("cannot unpack a Variable iterable" "without knowing its length")
elif expected_length is not None:
w_len = self.len(w_iterable)
w_correct = self.eq(w_len, self.wrap(expected_length))
if not self.is_true(w_correct):
e = OperationError(self.w_ValueError, self.w_None)
e.normalize_exception(self)
raise e
return [self.do_operation("getitem", w_iterable, self.wrap(i)) for i in range(expected_length)]
return ObjSpace.unpackiterable(self, w_iterable, expected_length)
示例6: fixedview
# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
def fixedview(self, w_obj, expected_length=-1, unroll=False):
""" Fast paths
"""
if isinstance(w_obj, W_AbstractTupleObject) and self._uses_tuple_iter(w_obj):
t = w_obj.tolist()
elif type(w_obj) is W_ListObject:
if unroll:
t = w_obj.getitems_unroll()
else:
t = w_obj.getitems_fixedsize()
else:
if unroll:
return make_sure_not_resized(ObjSpace.unpackiterable_unroll(self, w_obj, expected_length))
else:
return make_sure_not_resized(ObjSpace.unpackiterable(self, w_obj, expected_length)[:])
if expected_length != -1 and len(t) != expected_length:
raise self._wrap_expected_length(expected_length, len(t))
return make_sure_not_resized(t)
示例7: unpackiterable
# 需要导入模块: from pypy.interpreter.baseobjspace import ObjSpace [as 别名]
# 或者: from pypy.interpreter.baseobjspace.ObjSpace import unpackiterable [as 别名]
def unpackiterable(self, w_iterable, expected_length=None):
if not isinstance(w_iterable, Variable):
l = list(self.unwrap(w_iterable))
if expected_length is not None and len(l) != expected_length:
raise ValueError
return [self.wrap(x) for x in l]
if isinstance(w_iterable, Variable) and expected_length is None:
raise UnwrapException, ("cannot unpack a Variable iterable"
"without knowing its length")
## # XXX TEMPORARY HACK XXX TEMPORARY HACK XXX TEMPORARY HACK
## print ("*** cannot unpack a Variable iterable "
## "without knowing its length,")
## print " assuming a list or tuple with up to 7 items"
## items = []
## w_len = self.len(w_iterable)
## i = 0
## while True:
## w_i = self.wrap(i)
## w_cond = self.eq(w_len, w_i)
## if self.is_true(w_cond):
## break # done
## if i == 7:
## # too many values
## raise OperationError(self.w_AssertionError, self.w_None)
## w_item = self.do_operation('getitem', w_iterable, w_i)
## items.append(w_item)
## i += 1
## return items
## # XXX TEMPORARY HACK XXX TEMPORARY HACK XXX TEMPORARY HACK
elif expected_length is not None:
w_len = self.len(w_iterable)
w_correct = self.eq(w_len, self.wrap(expected_length))
if not self.is_true(w_correct):
e = OperationError(self.w_ValueError, self.w_None)
e.normalize_exception(self)
raise e
return [self.do_operation('getitem', w_iterable, self.wrap(i))
for i in range(expected_length)]
return ObjSpace.unpackiterable(self, w_iterable, expected_length)