Skip to content

Commit

Permalink
Fixed Flake8 error E721: use 'isinstance()' to compare types
Browse files Browse the repository at this point in the history
  • Loading branch information
flozz committed Aug 22, 2023
1 parent 32800c5 commit d1b6ef4
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions rivalcfg/handlers/buttons/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ def process_value(setting_info, mapping):
"""
# -- Parse input values

if type(mapping) is str and REGEXP_PARAM_STRING.match(mapping):
if isinstance(mapping, str) and REGEXP_PARAM_STRING.match(mapping):
is_valid, reason = is_buttons(mapping, setting_info)
if not is_valid:
raise ValueError(reason)
mapping = parse_param_string(mapping)
elif type(mapping) is str and mapping.lower() == "default":
elif isinstance(mapping, str) and mapping.lower() == "default":
mapping = {"buttons": {}}
elif type(mapping) is dict:
elif isinstance(mapping, dict):
pass
else:
raise ValueError("Invalid input value '%s'" % str(mapping))
Expand Down
2 changes: 1 addition & 1 deletion rivalcfg/handlers/choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def choices_to_list(choices):
return list(
map(
str,
sorted(choices.keys(), key=lambda v: v if type(v) == int else -1),
sorted(choices.keys(), key=lambda v: v if isinstance(v, int) else -1),
)
)

Expand Down
4 changes: 2 additions & 2 deletions rivalcfg/handlers/multidpi_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def process_value(setting_info, value, selected_preset=None):
"""
dpis = []

if type(value) in (int, float):
if isinstance(value, (int, float)):
dpis = [int(value)]
elif type(value) in (list, tuple):
elif isinstance(value, (list, tuple)):
dpis = [int(dpi) for dpi in value]
else:
dpis = [int(dpi) for dpi in value.replace(" ", "").split(",")]
Expand Down
4 changes: 2 additions & 2 deletions rivalcfg/handlers/reactive_rgbcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def process_value(setting_info, color):
return [0x00, 0x00, 0x00, 0x00, 0x00]

# Color tuple
if type(color) in (tuple, list):
if isinstance(color, (tuple, list)):
if len(color) != 3:
raise ValueError("Not a valid color %s" % str(color))
for channel in color:
if type(channel) != int or channel < 0 or channel > 255:
if not isinstance(channel, int) or channel < 0 or channel > 255:
raise ValueError("Not a valid color %s" % str(color))
return [0x01, 0x00] + list(color)
if is_color(color):
Expand Down
4 changes: 2 additions & 2 deletions rivalcfg/handlers/rgbcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def process_value(setting_info, color):
:rtype: [int, int, int]
"""
# Color tuple
if type(color) in (tuple, list):
if isinstance(color, (tuple, list)):
if len(color) != 3:
raise ValueError("Not a valid color %s" % str(color))
for channel in color:
if type(channel) != int or channel < 0 or channel > 255:
if not isinstance(channel, int) or channel < 0 or channel > 255:
raise ValueError("Not a valid color %s" % str(color))
return list(color)

Expand Down
14 changes: 7 additions & 7 deletions rivalcfg/handlers/rgbgradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _handle_color_tuple(color):
if len(color) != 3:
raise ValueError("Not a valid color %s" % str(color))
for channel in color:
if type(channel) != int or channel < 0 or channel > 255:
if not isinstance(channel, int) or channel < 0 or channel > 255:
raise ValueError("Not a valid color %s" % str(color))
return [
{
Expand Down Expand Up @@ -149,12 +149,12 @@ def _handle_rgbgradient_dict(colors):
if "colors" in colors:
for stop in colors["colors"]:
color = stop["color"]
if type(color) is str:
if isinstance(color, str):
color = parse_color_string(color)
if type(color) not in [tuple, list] or len(color) != 3:
if not isinstance(color, (tuple, list)) or len(color) != 3:
raise ValueError("Not a valid color %s" % str(color))
for channel in color:
if type(channel) != int or channel < 0 or channel > 255:
if not isinstance(channel, int) or channel < 0 or channel > 255:
raise ValueError("Not a valid color %s" % str(color))
gradient.append(
{
Expand Down Expand Up @@ -214,17 +214,17 @@ def process_value(setting_info, colors):
gradient = []

# Color tuple
if type(colors) in (tuple, list):
if isinstance(colors, (tuple, list)):
is_gradient = False
gradient = _handle_color_tuple(colors)

# Simple color string
elif type(colors) is str and is_color(colors):
elif isinstance(colors, str) and is_color(colors):
is_gradient = False
gradient = _handle_color_string(colors)

# Color gradient as dict
elif type(colors) is dict:
elif isinstance(colors, dict):
is_gradient = True
duration, gradient = _handle_rgbgradient_dict(colors)

Expand Down
6 changes: 3 additions & 3 deletions rivalcfg/handlers/rgbgradientv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ def process_value(setting_info, colors):
gradient = []

# Color tuple
if type(colors) in (tuple, list):
if isinstance(colors, (tuple, list)):
gradient = _handle_color_tuple(colors)

# Simple color string
elif type(colors) is str and is_color(colors):
elif isinstance(colors, str) and is_color(colors):
gradient = _handle_color_string(colors)

# Color gradient as dict
elif type(colors) is dict:
elif isinstance(colors, dict):
duration, gradient = _handle_rgbgradient_dict(colors)

# Color gradient as string
Expand Down
2 changes: 1 addition & 1 deletion rivalcfg/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def merge_bytes(*args):
"""
result = []
for arg in args:
if type(arg) in [list, tuple]:
if isinstance(arg, (list, tuple)):
result.extend(arg)
else:
result.append(arg)
Expand Down

0 comments on commit d1b6ef4

Please sign in to comment.