refactor: replace multiple == checks with in (#5737)

To check if a variable is equal to one of many values, combine the values into a tuple and check if the variable is contained `in` it instead of checking for equality against each of the values.
This is faster, less verbose, and more readable.

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
This commit is contained in:
Matthias Mair 2023-10-17 22:30:16 +02:00 committed by GitHub
parent faac6b6bf5
commit 3f93151cca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 9 deletions

View File

@ -289,11 +289,9 @@ class PartCategoryAPITest(InvenTreeAPITestCase):
delete_child_categories: bool = False
delete_parts: bool = False
if i == Target.move_subcategories_to_parent_delete_parts \
or i == Target.delete_subcategories_delete_parts:
if i in (Target.move_subcategories_to_parent_delete_parts, Target.delete_subcategories_delete_parts):
delete_parts = True
if i == Target.delete_subcategories_move_parts_to_parent \
or i == Target.delete_subcategories_delete_parts:
if i in (Target.delete_subcategories_move_parts_to_parent, Target.delete_subcategories_delete_parts):
delete_child_categories = True
# Create a parent category

View File

@ -480,7 +480,7 @@ class PluginsRegistry:
# - If this plugin has been explicitly enabled by the user
if settings.PLUGIN_TESTING or builtin or (plg_db and plg_db.active):
# Check if the plugin was blocked -> threw an error; option1: package, option2: file-based
if disabled and ((plg.__name__ == disabled) or (plg.__module__ == disabled)):
if disabled and disabled in (plg.__name__, plg.__module__):
safe_reference(plugin=plg, key=plg_key, active=False)
continue # continue -> the plugin is not loaded

View File

@ -137,11 +137,9 @@ class StockLocationTest(StockAPITestCase):
delete_sub_locations: bool = False
delete_stock_items: bool = False
if i == Target.move_sub_locations_to_parent_delete_stockitems \
or i == Target.delete_sub_locations_delete_stockitems:
if i in (Target.move_sub_locations_to_parent_delete_stockitems, Target.delete_sub_locations_delete_stockitems):
delete_stock_items = True
if i == Target.delete_sub_locations_move_stockitems_to_parent \
or i == Target.delete_sub_locations_delete_stockitems:
if i in (Target.delete_sub_locations_move_stockitems_to_parent, Target.delete_sub_locations_delete_stockitems):
delete_sub_locations = True
# Create a parent stock location