[New-bugs-announce] [issue35611] open doesn't call IncrementalEncoder with final=True

David Haney report at bugs.python.org
Sat Dec 29 01:00:15 EST 2018


New submission from David Haney <david.haney at gmail.com>:

The implementation of open relies on a codecs' IncrementalEncoder, however it never calls `encode` with final=True. This appears to violate the documentation for IncrementalEncoder.encode which states that the last call to encode _must_ set final=True.

The attached test case demonstrates this behavior. A codec "delayed" is implemented that holds the last encoded string until the next call to `encode`, at which point it returns the encoded string. When final=True, both the previous and current string are returned.

When `codecs.iterencode` is used to encode a sequence of strings, the encode function is called for each element in the sequence, with final=False. encode is then called a final time with an empty string and final=True.

When `open` is used to open a file stream for the encoding, each call to `write` calls `encode` with final=False, however it never calls `encode` with final=True, and it doesn't appear there's an API for forcing it to occur (for instance `flush` and `close` do not).

----------
components: IO
files: test.py
messages: 332701
nosy: haney
priority: normal
severity: normal
status: open
title: open doesn't call IncrementalEncoder with final=True
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48022/test.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35611>
_______________________________________


More information about the New-bugs-announce mailing list