Bytearray support

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Bytearray support

Post by marfis » Fri Nov 28, 2014 4:39 pm

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?

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Bytearray support

Post by marfis » Sat Nov 29, 2014 11:52 am

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?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Bytearray support

Post by dhylands » Sat Nov 29, 2014 6:18 pm

I filed an issue on github, that links to this conversation:
https://github.com/micropython/micropython/issues/994

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Bytearray support

Post by marfis » Mon Dec 01, 2014 8:22 pm

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!

Post Reply