Author: mattip <matti.pi...@gmail.com> Branch: Changeset: r72432:46446b3987d3 Date: 2014-07-14 07:10 +0300 http://bitbucket.org/pypy/pypy/changeset/46446b3987d3/
Log: implement __iter__for scalars (yuyichao) diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py --- a/pypy/module/micronumpy/boxes.py +++ b/pypy/module/micronumpy/boxes.py @@ -153,12 +153,10 @@ raise OperationError(space.w_IndexError, space.wrap( "invalid index to scalar variable")) - ''' def descr_iter(self, space): # Making numpy scalar non-iterable with a valid __getitem__ method raise oefmt(space.w_TypeError, "'%T' object is not iterable", self) - ''' def descr_str(self, space): return space.wrap(self.get_dtype(space).itemtype.str_format(self)) @@ -513,6 +511,9 @@ return space.wrap(dtype.itemtype.to_str(read_val)) return read_val + def descr_iter(self, space): + return space.newseqiter(self) + def descr_setitem(self, space, w_item, w_value): if space.isinstance_w(w_item, space.w_basestring): item = space.str_w(w_item) @@ -562,7 +563,7 @@ __new__ = interp2app(W_GenericBox.descr__new__.im_func), __getitem__ = interp2app(W_GenericBox.descr_getitem), - #__iter__ = interp2app(W_GenericBox.descr_iter), + __iter__ = interp2app(W_GenericBox.descr_iter), __str__ = interp2app(W_GenericBox.descr_str), __repr__ = interp2app(W_GenericBox.descr_str), __format__ = interp2app(W_GenericBox.descr_format), @@ -784,6 +785,7 @@ __new__ = interp2app(W_VoidBox.descr__new__.im_func), __getitem__ = interp2app(W_VoidBox.descr_getitem), __setitem__ = interp2app(W_VoidBox.descr_setitem), + __iter__ = interp2app(W_VoidBox.descr_iter), ) W_CharacterBox.typedef = TypeDef("numpy.character", W_FlexibleBox.typedef, diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -292,7 +292,6 @@ assert np.isnan(b/a) def test_scalar_iter(self): - skip('not implemented yet') from numpypy import int8, int16, int32, int64, float32, float64 for t in int8, int16, int32, int64, float32, float64: try: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit