[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

Terry J. Reedy report at bugs.python.org
Thu Jun 23 02:08:33 CEST 2011


Terry J. Reedy <tjreedy at udel.edu> added the comment:

After thinking about this awhile, I see the key sentence of David's reply as "The data type of the arguments to the method have no necessary relationship with the datatype of the object." While true in general, in it not true with respect to corresponing text (string) and byte(array) methods. String parameters of strings methods become byte parameters of byte(array) methods. In the other hand, I think I agree with David's application to byte versus bytearray methods. I might change my mind after further examination of the methods in question. But for the present, I would not change the code.

Or would I? Here is a reason not to change. Example:

for byt in (b'abc', bytearray(b'cdef'), b'xye')
  yield byt.rjust(10,b'-')

Making the type of constant args depend on the type of the base object would make generic byte/bytearray functions more difficult. We already have this problem with writing functions that work with bytes and text in 3.x. It is a big nuisance that is only justified by the benefits of not mixing bytes and text. I do not think we should extend the nuisance to byte and bytearray functions, especially without a strong use case.

I marked this for 'documentation' because I think the doc for some of the str methods might be improved and that the reference to them in the bytes/bytearray definitely needs more. Doc changes would apply to 3.2 also.

"Bytes and bytearray objects, being “strings of bytes”, have all methods found on strings, with the exception ... " 

should be followed by something like. 

"If the string method has a string parameter, the corresponding byte/bytearray method has a corresponding byte parameter."

(to match the reported current behavior).

I have not yet looked at doc strings. I did not unmark 'Interpreter core' because I have not looked at all of p.u's examples to be sure that I like *all* of the current behaviors.

----------
assignee:  -> docs at python
components: +Documentation
nosy: +docs at python
resolution: rejected -> 

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12380>
_______________________________________


More information about the Python-bugs-list mailing list