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
decoding functions in _codecs module accept str arguments #49124
Using run_tests.sh, all tests are ok (with 19 skipped tests). I guess
that there is not tests for all these functions :-/
Note: codecs documentation was already correct:
.. method:: Codec.decode(input[, errors])
(...)
*input* must be a bytes object or one which provides the read-only
character
buffer interface -- for example, buffer objects and memory mapped
files.
These changes are in line with their C API codec interfaces as well,
but those particular codecs could well also be made to work on Unicode
input, since unescaping can well be applied to Unicode as well.
I'll probably open a new item for this.
Using run_tests.sh, all tests are ok (with 19 skipped tests). I guess
that there is not tests for all these functions :-/
The mbcs codec is only available on Windows.
All others are tested by test_codecs.py.
Which ones are skipped in your case ?
Note: codecs documentation was already correct:
.. method:: Codec.decode(input[, errors])
(...)
*input* must be a bytes object or one which provides the read-only
character
buffer interface -- for example, buffer objects and memory mapped
files.
That's not entirely correct: codecs are allowed to accept any
object type and can also return any object type. It up to them
to decide, e.g. a codec may accept both bytes and Unicode input
and always generate Unicode output when decoding.
TypeError: decode() argument 1 must be bytes or buffer, not str
Since the test is meant to test recovery from a misbehaving callback, I
guess the type of the input string is not really important and can be
changed to a bytes string instead. What do you think?
The patch looks good.
I think the missing b in test_errorcallback_longindex is an overlook
when the tests were updated for py3k. You are right to change the test.
Activity
pitrou commentedon Jan 7, 2009
The following function calls should raise a TypeError instead. Encoding
functions are fine (they only accept str).
vstinner commentedon Jan 8, 2009
Patch replacing "s*" parsing format by "y*" for:
Using run_tests.sh, all tests are ok (with 19 skipped tests). I guess
that there is not tests for all these functions :-/
Note: codecs documentation was already correct:
.. method:: Codec.decode(input[, errors])
(...)
*input* must be a bytes object or one which provides the read-only
character
buffer interface -- for example, buffer objects and memory mapped
files.
malemburg commentedon Jan 8, 2009
On 2009-01-08 01:59, STINNER Victor wrote:
These are fine.
These changes are in line with their C API codec interfaces as well,
but those particular codecs could well also be made to work on Unicode
input, since unescaping can well be applied to Unicode as well.
I'll probably open a new item for this.
The mbcs codec is only available on Windows.
All others are tested by test_codecs.py.
Which ones are skipped in your case ?
That's not entirely correct: codecs are allowed to accept any
object type and can also return any object type. It up to them
to decide, e.g. a codec may accept both bytes and Unicode input
and always generate Unicode output when decoding.
I guess I have to review those doc changes...
pitrou commentedon Jan 13, 2009
The patch is probably fine, but it would be nice to add some unit tests
for the new behaviour.
malemburg commentedon Jan 14, 2009
On 2009-01-13 14:14, Antoine Pitrou wrote:
+1 from my side.
Thanks for the patch, Viktor.
vstinner commentedon Jan 17, 2009
New patch:
unchanged (still accept unicode string)
raw_unicode_escape_decode() (there was no test for these functions)
pitrou commentedon Jan 22, 2009
Committed in r68855, r68856. Thanks!
amauryfa commentedon Jan 22, 2009
IMO, Modules/cjkcodecs/multibytecodec.c should be changed as well.
pitrou commentedon Jan 22, 2009
Right, I hadn't thought of that.
pitrou commentedon Jan 22, 2009
"Fixing" multibytecodec.c produces a TypeError in the following test:
TypeError: decode() argument 1 must be bytes or buffer, not str
Since the test is meant to test recovery from a misbehaving callback, I
guess the type of the input string is not really important and can be
changed to a bytes string instead. What do you think?
(in any case, here is a patch)
amauryfa commentedon Jan 22, 2009
The patch looks good.
I think the missing b in test_errorcallback_longindex is an overlook
when the tests were updated for py3k. You are right to change the test.
pitrou commentedon Jan 22, 2009
Committed in r68857, r68858.