[issue23231] Fix codecs.iterencode/decode() by allowing data parameter to be omitted

Martin Panter report at bugs.python.org
Fri Aug 19 05:06:30 EDT 2016


Martin Panter added the comment:

Serhiy’s two proposals won’t work for codecs that include non-zero output for zero input:

>>> tuple(iterencode((), "utf-8-sig"))
(b'\xef\xbb\xbf',)
>>> encode(b"", "uu")
b'begin 666 <data>\n \nend\n'
>>> encode(b"", "zlib")
b'x\x9c\x03\x00\x00\x00\x00\x01'

However I agree that changing the incremental codec APIs is not ideal. Since nobody seems to care that much, it might be simpler to document that:

* iterencode() only works where text str objects can be encoded, so base64-codec is not supported, but rot13-codec is supported
* iterdecode() only works where bytes objects can be decoded, so rot13-codec is not supported, but base64-codec should be supported (pending other aspects of Issue 20132)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23231>
_______________________________________


More information about the Python-bugs-list mailing list