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.

classification
Title: bytes type has inconsistent methods (append, insert)
Type: behavior Stage:
Components: Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: akuchling, brunogola, georg.brandl
Priority: normal Keywords: patch

Created on 2008-06-20 23:34 by akuchling, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue3156.patch brunogola, 2008-06-21 20:26 patch for issue 3156
Messages (3)
msg68487 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2008-06-20 23:34
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 "<stdin>", line 1, in <module>                                  
        
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.
msg68538 - (view) Author: Bruno Gola (brunogola) Date: 2008-06-21 20:26
The following patch fixes the behavior, .append and .insert will accept
only integer as parameters.

Is this really the desired behavior? I mean, why not to accept a
character for both methods?

There are two tests in Lib/test/test_io.py that uses the old behavior
for .append().
msg69856 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-07-16 23:32
Fixed in 2.6 r65041, and 3k r65043.
History
Date User Action Args
2022-04-11 14:56:35adminsetgithub: 47406
2008-07-16 23:32:47georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg69856
nosy: + georg.brandl
2008-06-21 20:26:19brunogolasetfiles: + issue3156.patch
nosy: + brunogola
messages: + msg68538
keywords: + patch
2008-06-20 23:34:59akuchlingcreate