Issue 1108272: Syntax for iterator slicing, concatenation and repetition (original) (raw)

Issue1108272

Created on 2005-01-24 11:17 by ncoghlan, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
iter_slice.diff ncoghlan,2005-01-24 11:17 Add PyIter_GetItem and use it in PyObject_GetItem
iter_ops.diff ncoghlan,2005-01-26 13:03 Syntactic support for iterator slicing, concatenation and repetition
test_iter_ops.py ncoghlan,2005-01-26 13:05 Trivial (print-out) test of iterator operations
Messages (3)
msg47605 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2005-01-24 11:17
This patch allows any iterable to automatically support subscripting. Simple indices (itr[n]) will consume the iterator, and return the n'th item produced. Slice indices (itr[start:stop:step]) will produce an itertools.islice object created with the appropriate arguments. It also adds the C API function PyIter_GetItem which implements the above, and is invoked by PyObject_GetItem. Built and trivially tested on Suse Linux 9.1 from current CVS. Documentation and tests still to be added (Wednesday is a public holiday, so I will hopefully get to them then).
msg47606 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2005-01-26 13:03
Logged In: YES user_id=1038590 In for a penny, in for a pound. The new patch adds support for iterator concatenation (PyIter_Concat) and iterator repetition (PyIter_Repeat), based on itertools.chain and itertools.cycle respectively. The latter required adding an optional "times" argument to itertools.cycle. Augmented assignment is not supported in this patch. I also tweaked the behaviour of PyIter_GetItem, so its error handling was more like that of PySequence_GetItem. Finally, added a trivial test script that is barely deserving of the name, but does show that the thing basically works. Further work (i.e. proper tests. documentation, and cleaning up the code) will be dependent on BDFL approval.
msg47607 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2005-03-12 02:55
Logged In: YES user_id=1038590 Rejecting this myself, due partially to Guido's objections, but also because I think this is better approached by offering a base class which makes syntactic manipulation of iterators more convenient (and possibly uses tee() internally).
History
Date User Action Args
2022-04-11 14:56:09 admin set github: 41480
2005-01-24 11:17:15 ncoghlan create