You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix codecs.iterencode/decode() by allowing data parameter to be omitted #67420
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/vadmium'closed_at=<Date2016-10-15.01:37:36.979>created_at=<Date2015-01-13.12:48:19.265>labels= ['type-bug', '3.7', 'expert-unicode', 'docs']
title='Fix codecs.iterencode/decode() by allowing data parameter to be omitted'updated_at=<Date2016-10-15.01:37:36.977>user='https://github.com/vadmium'
As mentioned in bpo-20132, iterencode() and iterdecode() only work on text-to-byte codecs, because they assume particular data types when finalizing the incremental codecs. This patch changes the signature of the IncrementalEncoder and IncrementalDecoder methods from
so that iteren/decode(), and perhaps in the future, StreamWriter/Reader, can operate the incremental codec without knowing what kind of data should be processed.
Original patch has lots of whitespace changes, probably due to generated codec code not being regenerated for a long time. This diff ignores the space changes, so should be easier to review.
Another idea that doesn’t involve changing the incremental codec APIs is kind of described in <https://bugs.python.org/issue7475#msg145986\>: to add format parameters to iterencode() and iterdecode(), which would allow it to determine the right data type to finalize the codecs with.
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 bpo-20132)
Activity
vadmium commentedon Jan 13, 2015
As mentioned in bpo-20132, iterencode() and iterdecode() only work on text-to-byte codecs, because they assume particular data types when finalizing the incremental codecs. This patch changes the signature of the IncrementalEncoder and IncrementalDecoder methods from
to
so that iteren/decode(), and perhaps in the future, StreamWriter/Reader, can operate the incremental codec without knowing what kind of data should be processed.
vadmium commentedon Jan 13, 2015
Original patch has lots of whitespace changes, probably due to generated codec code not being regenerated for a long time. This diff ignores the space changes, so should be easier to review.
vadmium commentedon Jan 18, 2015
Another idea that doesn’t involve changing the incremental codec APIs is kind of described in <https://bugs.python.org/issue7475#msg145986\>: to add format parameters to iterencode() and iterdecode(), which would allow it to determine the right data type to finalize the codecs with.
serhiy-storchaka commentedon Dec 19, 2015
The patch changes public interface. This breaks compatibility with third-party codecs implementing it.
We have found other solution to iterencode/iterdecode problem. For example we can buffer iterated values and encode with one step delay:
Or remember the previous value and use it to calculate the empty value at the end (works only if input type supports slicing):
vadmium commentedon Aug 19, 2016
Serhiy’s two proposals won’t work for codecs that include non-zero output for zero input:
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:
vadmium commentedon Aug 20, 2016
Here is my documentation proposal.
serhiy-storchaka commentedon Aug 20, 2016
Agreed.
python-dev commentedon Oct 15, 2016
New changeset 402eba63650c by Martin Panter in branch '3.5':
Issue bpo-23231: Document codecs.iterencode(), iterdecode() shortcomings
https://hg.python.org/cpython/rev/402eba63650c
New changeset 0837940bcb9f by Martin Panter in branch '3.6':
Issue bpo-23231: Merge codecs doc from 3.5 into 3.6
https://hg.python.org/cpython/rev/0837940bcb9f
New changeset 1955dcc27332 by Martin Panter in branch 'default':
Issue bpo-23231: Merge codecs doc from 3.6
https://hg.python.org/cpython/rev/1955dcc27332