[Python-checkins] CVS: python/nondist/peps pep-0234.txt,1.10,1.11
Guido van Rossum
gvanrossum@users.sourceforge.net
Tue, 01 May 2001 04:42:09 -0700
Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv2159
Modified Files:
pep-0234.txt
Log Message:
Correct typos and add bits of discussion. Also add another "chief
virtue".
Index: pep-0234.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0234.txt,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** pep-0234.txt 2001/05/01 02:29:03 1.10
--- pep-0234.txt 2001/05/01 11:42:07 1.11
***************
*** 20,24 ****
In addition, specific iterators over the keys of a dictionary and
over the lines of a file are proposed, and a proposal is made to
! allow spelling dict.kas_key(key) as "key in dict".
Note: this is an almost complete rewrite of this PEP by the second
--- 20,24 ----
In addition, specific iterators over the keys of a dictionary and
over the lines of a file are proposed, and a proposal is made to
! allow spelling dict.has_key(key) as "key in dict".
Note: this is an almost complete rewrite of this PEP by the second
***************
*** 117,128 ****
next value from the iterator. If the callable raises an
exception, this is propagated normally; in particular, the
! function is allowed to raise StopError as an alternative way to
! end the iteration. (This functionality is available from the C
! API as PyCallIter_New(callable, sentinel).)
Iterator objects returned by either form of iter() have a next()
method. This method either returns the next value in the
! iteration, or raises StopError (or a derived exception class) to
! signal the end of the iteration. Any other exception should be
considered to signify an error and should be propagated normally,
not taken to mean the end of the iteration.
--- 117,128 ----
next value from the iterator. If the callable raises an
exception, this is propagated normally; in particular, the
! function is allowed to raise StopIteration as an alternative way
! to end the iteration. (This functionality is available from the
! C API as PyCallIter_New(callable, sentinel).)
Iterator objects returned by either form of iter() have a next()
method. This method either returns the next value in the
! iteration, or raises StopIteration (or a derived exception class)
! to signal the end of the iteration. Any other exception should be
considered to signify an error and should be propagated normally,
not taken to mean the end of the iteration.
***************
*** 213,221 ****
If all the parts of the proposal are included, this addresses many
concerns in a consistent and flexible fashion. Among its chief
! virtues are the following three -- no, four -- no, five -- points:
1. It provides an extensible iterator interface.
! 1. It allows performance enhancements to list iteration.
3. It allows big performance enhancements to dictionary iteration.
--- 213,221 ----
If all the parts of the proposal are included, this addresses many
concerns in a consistent and flexible fashion. Among its chief
! virtues are the following four -- no, five -- no, six -- points:
1. It provides an extensible iterator interface.
! 2. It allows performance enhancements to list iteration.
3. It allows big performance enhancements to dictionary iteration.
***************
*** 229,233 ****
--- 229,236 ----
{__getitem__, keys, values, items}.
+ 6. It makes code iterating over non-sequence collections more
+ concise and readable.
+
Open Issues
***************
*** 235,244 ****
- The name iter() is an abbreviation. Alternatives proposed
! include iterate(), harp(), traverse(), narrate().
- Using the same name for two different operations (getting an
iterator from an object and making an iterator for a function
with an sentinel value) is somewhat ugly. I haven't seen a
! better name for the second operation though.
- Once a particular iterator object has raised StopIteration, will
--- 238,250 ----
- The name iter() is an abbreviation. Alternatives proposed
! include iterate(), traverse(), but these appear too long.
! Python has a history of using abbrs for common builtins,
! e.g. repr(), str(), len().
- Using the same name for two different operations (getting an
iterator from an object and making an iterator for a function
with an sentinel value) is somewhat ugly. I haven't seen a
! better name for the second operation though, and since they both
! return an iterator, it's easy to remember.
- Once a particular iterator object has raised StopIteration, will
***************
*** 287,292 ****
dict" and "if x in dict" too compelling to break, and there's not
much overhead in having to write dict[x] to explicitly get the
! value. We could also add methods to dictionaries that return
! different kinds of iterators, e.g.
for key, value in dict.iteritems(): ...
--- 293,308 ----
dict" and "if x in dict" too compelling to break, and there's not
much overhead in having to write dict[x] to explicitly get the
! value. I've also timed the difference between
!
! for key in dict: dict[key]
!
! and
!
! for key, value in dict[key]: pass
!
! and found that these run at about the same speed.
!
! We could also add methods to dictionaries that return different
! kinds of iterators, e.g.
for key, value in dict.iteritems(): ...