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>
This commit is contained in:
parent
d529c20674
commit
597fcb4751
@ -33,9 +33,9 @@ if platform.python_version_tuple()[0] == "2":
|
|||||||
|
|
||||||
str_cons = lambda val, enc=None: str(val)
|
str_cons = lambda val, enc=None: str(val)
|
||||||
bytes_cons = lambda val, enc=None: bytearray(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_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):
|
def hexlify_to_str(b):
|
||||||
x = hexlify_py2(b)
|
x = hexlify_py2(b)
|
||||||
@ -46,9 +46,9 @@ else:
|
|||||||
|
|
||||||
str_cons = str
|
str_cons = str
|
||||||
bytes_cons = bytes
|
bytes_cons = bytes
|
||||||
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 bytes
|
is_bytes_type = lambda o: isinstance(o, bytes)
|
||||||
is_int_type = lambda o: type(o) is int
|
is_int_type = lambda o: isinstance(o, int)
|
||||||
|
|
||||||
def hexlify_to_str(b):
|
def hexlify_to_str(b):
|
||||||
return str(hexlify(b, ":"), "ascii")
|
return str(hexlify(b, ":"), "ascii")
|
||||||
@ -756,7 +756,7 @@ class CompiledModule:
|
|||||||
const_int_content += (digs.count(",") + 1) * bits_per_dig // 8
|
const_int_content += (digs.count(",") + 1) * bits_per_dig // 8
|
||||||
const_obj_content += 4 * 4
|
const_obj_content += 4 * 4
|
||||||
return "MP_ROM_PTR(&%s)" % obj_name
|
return "MP_ROM_PTR(&%s)" % obj_name
|
||||||
elif type(obj) is float:
|
elif isinstance(obj, float):
|
||||||
macro_name = "%s_macro" % obj_name
|
macro_name = "%s_macro" % obj_name
|
||||||
print(
|
print(
|
||||||
"#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B"
|
"#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B"
|
||||||
@ -777,7 +777,7 @@ class CompiledModule:
|
|||||||
print("#endif")
|
print("#endif")
|
||||||
const_obj_content += 3 * 4
|
const_obj_content += 3 * 4
|
||||||
return macro_name
|
return macro_name
|
||||||
elif type(obj) is complex:
|
elif isinstance(obj, complex):
|
||||||
print(
|
print(
|
||||||
"static const mp_obj_complex_t %s = {{&mp_type_complex}, (mp_float_t)%.16g, (mp_float_t)%.16g};"
|
"static const mp_obj_complex_t %s = {{&mp_type_complex}, (mp_float_t)%.16g, (mp_float_t)%.16g};"
|
||||||
% (obj_name, obj.real, obj.imag)
|
% (obj_name, obj.real, obj.imag)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user