msg153354 - (view) |
Author: Jim Jewett (Jim.Jewett) *  |
Date: 2012-02-14 18:01 |
def reset(self): """ Flushes and resets the codec buffers used for keeping state. Calling this method should ensure that the data on the output is put into a clean state, that allows appending of new fresh data without having to rescan the whole stream to recover state. """ pass This does not ensure that the stream is flushed, as the docstring promises. I believe the following would work better. def reset(self): """ Flushes and resets the codec buffers used for keeping state. Calling this method should ensure that the data on the output is put into a clean state, that allows appending of new fresh data without having to rescan the whole stream to recover state. """ if hasattr(self.stream, "flush"): self.stream.flush() |
|
|
msg222178 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2014-07-03 13:50 |
On Windows 7 206 codecs tests passed and 4 skipped with the patch included. |
|
|
msg233988 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2015-01-14 01:21 |
I don’t think this is appropriate. If you want to flush the underlying stream, then call its flush() method after calling reset(). The docstring only says it flushes the _codec’s_ buffers, not any buffers of the underlying stream, and it should not be the codec’s business to worry about lower level buffers. |
|
|
msg233994 - (view) |
Author: Jim Jewett (Jim.Jewett) *  |
Date: 2015-01-14 01:37 |
That sounds like a bug magnet to me; my mental model is that the codec is my output; flushing it will push things out, and resetting it will erase anything pending. I don't care if some implementation detail means that some other object technically owns the buffer. An alternative (inferior, but better than nothing) would be to add an explicit note warning users that reset won't really finish the job, and they have to also get the codec's underlying stream and flush that. (Of course, if the stream is really an abstraction over the real stream ... at what point does the delegation start to work on its own?) On Tue, Jan 13, 2015 at 8:21 PM, Martin Panter <report@bugs.python.org> wrote: > > Martin Panter added the comment: > > I don’t think this is appropriate. If you want to flush the underlying stream, then call its flush() method after calling reset(). The docstring only says it flushes the _codec’s_ buffers, not any buffers of the underlying stream, and it should not be the codec’s business to worry about lower level buffers. > > ---------- > nosy: +vadmium > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue14014> > _______________________________________ |
|
|
msg233999 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2015-01-14 02:26 |
Maybe it would be better to redefine the docstring to say it flushes the codec as well as calling flush() on the underlying stream. But if you really want to finish the job you should probably be closing the underlying stream, which would flush if necessary. See Issue 460474, for adding a close() method which invokes reset(). |
|
|
msg234014 - (view) |
Author: Marc-Andre Lemburg (lemburg) *  |
Date: 2015-01-14 08:34 |
On 14.01.2015 02:21, Martin Panter wrote: > > Martin Panter added the comment: > > I don’t think this is appropriate. If you want to flush the underlying stream, then call its flush() method after calling reset(). The docstring only says it flushes the _codec’s_ buffers, not any buffers of the underlying stream, and it should not be the codec’s business to worry about lower level buffers. Correct. That's the reason why the method is called .reset() and not .flush(). |
|
|
msg234015 - (view) |
Author: Marc-Andre Lemburg (lemburg) *  |
Date: 2015-01-14 08:41 |
Adding a note to the documentation is fine. The .reset() method doesn't have anything to do with the underlying stream. It's only meant to work at the codec level and needed for codecs that keep internal state. |
|
|
msg359849 - (view) |
Author: Cheryl Sabella (cheryl.sabella) *  |
Date: 2020-01-12 14:21 |
@lemburg, when you get a chance, please review the PR. Thanks! |
|
|
msg384464 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2021-01-06 02:14 |
New changeset 1a9f51ed12feb4d95ad6d0faf610a030c05b9f5e by Berker Peksag in branch 'master': bpo-14014: Clarify StreamWriter.reset() documentation (GH-13716) https://github.com/python/cpython/commit/1a9f51ed12feb4d95ad6d0faf610a030c05b9f5e |
|
|
msg384465 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2021-01-06 02:27 |
New changeset a3ca6747f50efa2fe59caf516a26b0fd1912b8e8 by Miss Islington (bot) in branch '3.9': bpo-14014: Clarify StreamWriter.reset() documentation (GH-13716) https://github.com/python/cpython/commit/a3ca6747f50efa2fe59caf516a26b0fd1912b8e8 |
|
|