From 3f93151cca4e4361c2171bb95faec80fa8e24052 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 17 Oct 2023 22:30:16 +0200 Subject: [PATCH] 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> --- InvenTree/part/test_api.py | 6 ++---- InvenTree/plugin/registry.py | 2 +- InvenTree/stock/test_api.py | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index 45a0dc46b5..e75709058a 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -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 diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 4cb8053a7b..5e9c29eb61 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -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 diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index 98b16882d5..9d518179b3 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -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