[issue8990] array constructor and array.fromstring should accept bytearray.

STINNER Victor report at bugs.python.org
Thu Jul 1 04:30:20 CEST 2010


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

array2.diff:
 - can you reindent the line "Py_ssize_t old_size = Py_SIZE(self);"?(even if it's not part of your patch)
 - you can avoid the "char *str;" variable (use directly buffer.buf)

--

> I changed "s#" to "y*". This means that str arguments are no longer
> accepted by fromstring (...) it is an incompatible change

It's maybe time to create .frombytes() and .tobytes() methods:

 - .tostring() will be a (deprecated?) alias to .tobytes()
 - .frombytes() only accepts bytes, bytearray and buffer compatible objects: use "y*" format
 - .fromstring() accepts str, bytes, bytearray and buffer compatible objects (encode str to utf-8): use "s*" format

But I still don't understand why array.fromstring() accepts character strings. So an easier solution is to apply array2.diff to Python 3.2, and replace "y*" by "s*" when the patch is applied to 3.1.

----------

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


More information about the Python-bugs-list mailing list