Ezio Melotti <ezio.melo...@gmail.com> added the comment:

Here is a proof of concept that fixes the problem.

The doc of bytearray() says about its first arg:
 * If it is a string, you must also give the encoding [...].
 * If it is an integer, the array will have that size and will be initialized 
with null bytes.
 * If it is an object conforming to the buffer interface, a read-only buffer of 
the object will be used to initialize the bytes array.
 * If it is an iterable, it must be an iterable of integers in the range 0 <= x 
< 256, which are used as the initial contents of the array.

All these things except the string[1] and the integer seem OK to me while 
assigning to a slice, so in the patch I've special-cased ints to raise a 
TypeError (it fails already for unicode strings).

[1]: note that string here means unicode string (the doc should probably be 
more specific about it.). Byte strings work fine, but for unicode strings 
there's no way to specify the encoding while doing ba[:] = u'ustring'.

----------
keywords: +patch
stage: needs patch -> unit test needed
Added file: http://bugs.python.org/file16945/issue8401.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8401>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to