Issue 3156: bytes type has inconsistent methods (append, insert) (original) (raw)

bytearray's methods aren't consistent in what they accept.

append() takes either an int or a character:

b = bytearray('abc')

b.append(76) ; b

bytearray(b'abcL')

b.append('M') ; b

bytearray(b'abcLM')

.insert() accepts only integers:

b.insert(0, 97) ; b

bytearray(b'aabcLM')

b.insert(0, 'a') ; b

Traceback (most recent call last):

File "", line 1, in

TypeError: an integer is required

Both PEP 358 and the docstring for .append() only document 'int' as a

legal input, so I suspect append() is wrong here.