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 eli.bendersky
Recipients docs@python, eli.bendersky, ncoghlan, petri.lehtinen, pitrou, py.user, r.david.murray, rhettinger, terry.reedy, vstinner
Date 2011-07-16.14:08:16
SpamBayes Score 7.3694314e-06
Marked as misclassified No
Message-id <>
On one hand, I agree that the situation isn't intuitive. Why should some methods of bytearray accept bytearrays, and some shouldn't?

On the other hand, this actually has rather deep implementation reasons. 

Methods like 'translate' are implemented in Objects/bytearrayobject.c

On the other hand, ljust, rjust and center are taken from stringlib. Now, stringlib is generic code, and has some strict argument checking. For example, in stringlib_ljust:

    if (!PyArg_ParseTuple(args, "n|c:ljust", &width, &fillchar))
        return NULL;

The 'c' format to PyArg_ParseTuple expects an object that passes PyBytes_Check, IOW a bytes object or a subclass thereof. bytearray is not a subclass of bytes, hence the problem.

The solution could be global, to allow bytearray fit the 'c' format of PyArg_ParseTuple. Then one would also be able to pass a bytearray into other stringlib methods requiring the 'c' format.

One way or the other, this is of course doable. A decision has to be made though - is the nuisance annoying enough to warrant such an API change?
Date User Action Args
2011-07-16 14:08:17eli.benderskysetrecipients: + eli.bendersky, rhettinger, terry.reedy, ncoghlan, pitrou, vstinner, r.david.murray, docs@python, py.user, petri.lehtinen
2011-07-16 14:08:17eli.benderskysetmessageid: <>
2011-07-16 14:08:16eli.benderskylinkissue12380 messages
2011-07-16 14:08:16eli.benderskycreate