Page 1 of 1

Bytearray support

Posted: Fri Nov 28, 2014 4:39 pm
by marfis
Not sure if this has been brought up already but:

Code: Select all

>>> a
bytearray(b'\x01\x02')
>>> b
bytearray(b'\x01\x02')
>>> a+b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand types for binary operator: 'bytearray', 'bytearray'
The help page of micropython's bytearray gives me:

Code: Select all

>>> help(bytearray)
object <class 'bytearray'> is of type type
  append -- <function>
not a lot here....

So am I correct that micropython's bytearray implementation differs from python 2.7 / 3.x?

Re: Bytearray support

Posted: Sat Nov 29, 2014 11:52 am
by marfis
So as a follow up, https://docs.python.org/3/library/stdty ... #binaryseq states that
As bytearray objects are mutable, they support the mutable sequence operations in addition to the common bytes and bytearray operations described in Bytes and Bytearray Operations.
mutable sequence operations include the extend operation for example. The common bytes and byte array operations also include the + operation.

Looking at objarray.c: If I interpret it correctly only the append function and binary operators are implemented. Is there a reason not to include the operations stated above? Or could anyone point me to restrictions on builtin datatypes, perhaps a summary on differences?

Re: Bytearray support

Posted: Sat Nov 29, 2014 6:18 pm
by dhylands
I filed an issue on github, that links to this conversation:
https://github.com/micropython/micropython/issues/994

Re: Bytearray support

Posted: Mon Dec 01, 2014 8:22 pm
by marfis
with uPy Version pybv10-2014-12-01-v1.3.7-12-g17c5ce3.dfu running:

Code: Select all

>>> a+b
bytearray(b'\x01\x02\x01\x02')
perfect - thanks!