QUERY · ISSUE
bytes.find() differs from CPython
py-core
In Cpython (at least) I can find by integer using bytes.find(). Micropython doesn't allow this and only acceptsbytes as an argument to find.
Micropython:
>>> s = b'ABC'
>>> s.find(b'B')
1
>>> s.find(66)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert 'int' object to str implicitly
>>>
Desktop python:
>>> s = b'ABC'
>>> s.find(b'B')
1
>>> s.find(66)
1
Here is the check that's failing, but additional code would be needed to convert int (0..255) into byte.
https://github.com/micropython/micropython/blob/master/py/objstr.c#L693
This bug bit me deep in some QR encoding logic.
CANDIDATE · ISSUE
'bytes()' function inconsistent with CPython for values > 255
Uncovered this issue while researching #1092
In uPy, when a value > 255 is passed to bytes() it is treated as though it were val % 256:
Micro Python v1.3.9-17-g57aebe1 on 2015-01-28; linux version
>>> bytes([255])
b'\xff'
>>> bytes([256])
b'\x00'
>>> bytes([257])
b'\x01'
>>>
In CPython, an exception is raised for values > 255:
>>> bytes([255])
b'\xff'
>>> bytes([256])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: bytes must be in range(0, 256)
>>>
Posting the issue for reference, but low importance until shown otherwise.