diff options
| author | Angus Gratton <angus@redyak.com.au> | 2023-08-09 17:41:54 +1000 |
|---|---|---|
| committer | Angus Gratton <angus@redyak.com.au> | 2023-08-09 17:41:54 +1000 |
| commit | 597fcb47518c842d445975961737832569fe3529 (patch) | |
| tree | 6926fc8cc9edd3df2f2c373084900121d3819135 | |
| parent | d529c20674131b9ce36853b92784e901a1bc86f4 (diff) | |
tools/mpy-tool.py: Use isinstance() for type checking.
Ruff version 283 expanded E721 to fail when making direct comparison
against a built-in type. Change the code to use isinstance() as
suggested, these usages appear to have equivalent functionality.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
| -rwxr-xr-x | tools/mpy-tool.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 7f581d0b1..a5112de9a 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -33,9 +33,9 @@ if platform.python_version_tuple()[0] == "2": str_cons = lambda val, enc=None: str(val) bytes_cons = lambda val, enc=None: bytearray(val) - is_str_type = lambda o: type(o) is str + is_str_type = lambda o: isinstance(o, str) is_bytes_type = lambda o: type(o) is bytearray - is_int_type = lambda o: type(o) is int or type(o) is long + is_int_type = lambda o: isinstance(o, int) or isinstance(o, long) def hexlify_to_str(b): x = hexlify_py2(b) @@ -46,9 +46,9 @@ else: str_cons = str bytes_cons = bytes - is_str_type = lambda o: type(o) is str - is_bytes_type = lambda o: type(o) is bytes - is_int_type = lambda o: type(o) is int + is_str_type = lambda o: isinstance(o, str) + is_bytes_type = lambda o: isinstance(o, bytes) + is_int_type = lambda o: isinstance(o, int) def hexlify_to_str(b): return str(hexlify(b, ":"), "ascii") @@ -756,7 +756,7 @@ class CompiledModule: const_int_content += (digs.count(",") + 1) * bits_per_dig // 8 const_obj_content += 4 * 4 return "MP_ROM_PTR(&%s)" % obj_name - elif type(obj) is float: + elif isinstance(obj, float): macro_name = "%s_macro" % obj_name print( "#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B" @@ -777,7 +777,7 @@ class CompiledModule: print("#endif") const_obj_content += 3 * 4 return macro_name - elif type(obj) is complex: + elif isinstance(obj, complex): print( "static const mp_obj_complex_t %s = {{&mp_type_complex}, (mp_float_t)%.16g, (mp_float_t)%.16g};" % (obj_name, obj.real, obj.imag) |
