This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients abacabadabacaba, ezio.melotti, loewis, pitrou
Date 2010-04-16.06:45:02
SpamBayes Score 3.6454173e-12
Marked as misclassified No
Message-id <1271400307.36.0.904341611442.issue8401@psf.upfronthosting.co.za>
In-reply-to
Content
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'.
History
Date User Action Args
2010-04-16 06:45:07ezio.melottisetrecipients: + ezio.melotti, loewis, pitrou, abacabadabacaba
2010-04-16 06:45:07ezio.melottisetmessageid: <1271400307.36.0.904341611442.issue8401@psf.upfronthosting.co.za>
2010-04-16 06:45:05ezio.melottilinkissue8401 messages
2010-04-16 06:45:04ezio.melotticreate