]> granicus.if.org Git - python/commitdiff
Backport r54712: document that calling file.next() on a file open for writing
authorBrett Cannon <bcannon@gmail.com>
Fri, 27 Apr 2007 22:35:57 +0000 (22:35 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 27 Apr 2007 22:35:57 +0000 (22:35 +0000)
leads to undefined behaviour.

Doc/lib/libstdtypes.tex
Misc/NEWS

index a4d38f9a280259995255dbd9cebbe9dca0cf1aec..e4486f465d1f8db522ea223acfc6a6e8cf2870d6 100644 (file)
@@ -1615,14 +1615,15 @@ A file object is its own iterator, for example \code{iter(\var{f})} returns
 iterator, typically in a \keyword{for} loop (for example,
 \code{for line in f: print line}), the \method{next()} method is
 called repeatedly.  This method returns the next input line, or raises
-\exception{StopIteration} when \EOF{} is hit.  In order to make a
-\keyword{for} loop the most efficient way of looping over the lines of
-a file (a very common operation), the \method{next()} method uses a
-hidden read-ahead buffer.  As a consequence of using a read-ahead
-buffer, combining \method{next()} with other file methods (like
-\method{readline()}) does not work right.  However, using
-\method{seek()} to reposition the file to an absolute position will
-flush the read-ahead buffer.
+\exception{StopIteration} when \EOF{} is hit when the file is open for
+reading (behavior is undefined when the file is open for writing).  In
+order to make a \keyword{for} loop the most efficient way of looping
+over the lines of a file (a very common operation), the
+\method{next()} method uses a hidden read-ahead buffer.  As a
+consequence of using a read-ahead buffer, combining \method{next()}
+with other file methods (like \method{readline()}) does not work
+right.  However, using \method{seek()} to reposition the file to an
+absolute position will flush the read-ahead buffer.
 \versionadded{2.3}
 \end{methoddesc}
 
index c0af38330f27c58f40cb39eadf2d951152cc3a68..bb8385f811fa8525899f12593d8dc2328fe0f3b7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,13 @@ Library
   run in verbose mode.
 
 
+Documentation
+-------------
+
+- Bug #1569057: Document that calling file.next() on a file open for writing
+  has undefined behaviour.  Backport of r54712.
+
+
 What's New in Python 2.5.1?
 =============================