py/objint: Allow int() to parse anything with the buffer protocol.

This generalises and simplifies the code and follows CPython behaviour.

See similar change for floats in a07fc5b640.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2023-05-23 18:02:32 +10:00
parent 66dc1397c9
commit 69dd013919
2 changed files with 16 additions and 5 deletions

12
tests/basics/int_parse.py Normal file
View File

@@ -0,0 +1,12 @@
# Test parsing ints.
try:
bytearray
memoryview
except NameError:
print("SKIP")
raise SystemExit
print(int(b"123"))
print(int(bytearray(b"123")))
print(int(memoryview(b"123")))