diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2022-11-07 12:55:31 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-11-08 23:09:22 +1100 |
commit | 2c8dab7ab4ec0884c6428afc613d9dcc322d8c6d (patch) | |
tree | 59add53a83983398bf59c82a71b78532f6ccadca /tests/basics/bytearray_construct.py | |
parent | f8b0ae32d31cfb95db4294c43b821c205c17e1d3 (diff) | |
download | micropython-2c8dab7ab4ec0884c6428afc613d9dcc322d8c6d.tar.gz micropython-2c8dab7ab4ec0884c6428afc613d9dcc322d8c6d.zip |
py/objarray: Detect bytearray(str) without an encoding.
This prevents a very subtle bug caused by writing e.g. `bytearray('\xfd')`
which gives you `(0xc3, 0xbd)`.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests/basics/bytearray_construct.py')
-rw-r--r-- | tests/basics/bytearray_construct.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tests/basics/bytearray_construct.py b/tests/basics/bytearray_construct.py index 75fdc41178..eb4d4e641f 100644 --- a/tests/basics/bytearray_construct.py +++ b/tests/basics/bytearray_construct.py @@ -5,3 +5,8 @@ print(bytearray('1234', 'utf-8')) print(bytearray('12345', 'utf-8', 'strict')) print(bytearray((1, 2))) print(bytearray([1, 2])) + +try: + print(bytearray('1234')) +except TypeError: + print("TypeError") |