QUERY · ISSUE
bytearray(length) does not validate length is >= 0
py-core
>>> bytearray(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 4294967295 bytes
This is pretty minor, since it does raise an error. CPython raises a ValueError instead:
>>> bytearray(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: negative count
CANDIDATE · ISSUE
Class `bytearray()` does not implement `count()`
enhancementpy-core
I just noticed that micropython apparently doesn't implement the count() method for class bytearray().
Since it's a basic built-in class/type and I didn't find it anywhere mentioned (docs/issues), I figured it might be worth dropping it here.
CPython:
bytearray(b'foobar').count(b'o')
2
MicroPython:
>>> bytearray(b'foobar').count(b'o')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'bytearray' object has no attribute 'count'