From 5501bbfbc4aac1f7bb1ee6c69eed7f07aba70a42 Mon Sep 17 00:00:00 2001 From: Yuanpeng Zhang Date: Wed, 6 Sep 2023 00:21:50 -0400 Subject: [PATCH] fix the new flake8 issues --- addie/post_process_m/event_handler.py | 4 +- addie/processing/mantid/launch_reduction.py | 56 +++++++++---------- .../master_table/master_table_loader.py | 2 +- tests/utilities/test_customtreeview.py | 2 +- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/addie/post_process_m/event_handler.py b/addie/post_process_m/event_handler.py index b5ec7269..c636c86a 100644 --- a/addie/post_process_m/event_handler.py +++ b/addie/post_process_m/event_handler.py @@ -702,7 +702,7 @@ def merge_banks(main_window): def save_file_raw(main_window, file_name): - if type(file_name) == list: + if file_name.isinstance(list): save_directory = QFileDialog.getExistingDirectory(main_window, 'Save Banks', main_window.current_folder) @@ -791,7 +791,7 @@ def save_file_merged(main_window, file_name, auto=False): def save_file_stog(main_window, file_name): - if type(file_name) == list: + if file_name.isinstance(list): save_directory = QFileDialog.getExistingDirectory(main_window, 'Save StoG Files', main_window.current_folder) diff --git a/addie/processing/mantid/launch_reduction.py b/addie/processing/mantid/launch_reduction.py index 6d1cc984..831fb526 100755 --- a/addie/processing/mantid/launch_reduction.py +++ b/addie/processing/mantid/launch_reduction.py @@ -672,7 +672,7 @@ def run_mantid(parent): elif "AlignAndFocusArgs" in key: af_tmp = {} for key_af, item_af in item.items(): - if type(item_af) == list: + if item_af.isinstance(list): try: list_tmp = [float(entry_tmp) for entry_tmp in item_af] except ValueError: @@ -743,8 +743,8 @@ def check_all_decimal(input_list): def check_all_number(input_list): for item in input_list: - cond1 = type(item) == int - cond2 = type(item) == float + cond1 = item.isinstance(int) + cond2 = type.isinstance(float) if not (cond1 or cond2): return False return True @@ -775,7 +775,7 @@ def final_validator(final_dict): # Check 'Sample' entry. if "Runs" in final_dict["Sample"]: - if type(final_dict["Sample"]["Runs"]) == str: + if final_dict["Sample"]["Runs"].isinstance(str): run_num_tmp = re.split("-|,| ", final_dict["Sample"]["Runs"]) if not check_all_decimal(run_num_tmp): log_error(2, '["Sample"]["Run"]') @@ -788,7 +788,7 @@ def final_validator(final_dict): return False if "Background" in final_dict["Sample"]: if "Runs" in final_dict["Sample"]["Background"] and "Background" in final_dict["Sample"]["Background"]: - if type(final_dict["Sample"]["Background"]["Runs"]) == str: + if final_dict["Sample"]["Background"]["Runs"].isinstance(str): bkg_run_num = re.split("-|,| ", final_dict["Sample"]["Background"]["Runs"]) if not check_all_decimal(bkg_run_num): log_error(2, '["Sample"]["Background"]["Runs"]') @@ -796,7 +796,7 @@ def final_validator(final_dict): else: log_error(2, '["Sample"]["Background"]["Runs"]') return False - if type(final_dict["Sample"]["Background"]["Background"]) == dict: + if final_dict["Sample"]["Background"]["Background"].isinstance(dict): if "Runs" in final_dict["Sample"]["Background"]["Background"]: bkg_run_num = re.split("-|,| ", final_dict["Sample"]["Background"]["Background"]["Runs"]) if not check_all_decimal(bkg_run_num): @@ -817,7 +817,7 @@ def final_validator(final_dict): else: if "Background" in final_dict["Normalization"]: if "Runs" in final_dict["Normalization"]["Background"]: - if type(final_dict["Normalization"]["Background"]["Runs"]) == str: + if final_dict["Normalization"]["Background"]["Runs"].isinstance(str): bkg_run_num = re.split("-|,| ", final_dict["Normalization"]["Background"]["Runs"]) if not check_all_decimal(bkg_run_num): log_error(2, '["Normalization"]["Background"]["Runs"]') @@ -834,15 +834,15 @@ def final_validator(final_dict): log_error(1, '["Sample"]["Background"]') return False if "Material" in final_dict["Sample"]: - if not type(final_dict["Sample"]["Material"]) == str: + if not final_dict["Sample"]["Material"].isinstance(str): log_error(2, '["Sample"]["Material"]') return False else: log_error(1, '["Sample"]["Material"]') if "MassDensity" in final_dict["Sample"]: cond1 = final_dict["Sample"]["MassDensity"] - cond2 = type(final_dict["Sample"]["MassDensity"]) == int - cond3 = type(final_dict["Sample"]["MassDensity"]) == float + cond2 = final_dict["Sample"]["MassDensity"].isinstance(int) + cond3 = final_dict["Sample"]["MassDensity"].isinstance(float) if not (cond1 and (cond2 or cond3)): log_error(2, '["Sample"]["MassDensity"]') return False @@ -850,8 +850,8 @@ def final_validator(final_dict): log_error(1, '["Sample"]["MassDensity"]') if "PackingFraction" in final_dict["Sample"]: cond1 = final_dict["Sample"]["PackingFraction"] - cond2 = type(final_dict["Sample"]["PackingFraction"]) == int - cond3 = type(final_dict["Sample"]["PackingFraction"]) == float + cond2 = final_dict["Sample"]["PackingFraction"].isinstance(int) + cond3 = final_dict["Sample"]["PackingFraction"].isinstance(float) if not (cond1 and (cond2 or cond3)): log_error(2, '["Sample"]["PackingFraction"]') return False @@ -860,14 +860,14 @@ def final_validator(final_dict): if "Geometry" in final_dict["Sample"]: if "Radius" in final_dict["Sample"]["Geometry"] and "Height" in final_dict["Sample"]["Geometry"]: cond1 = final_dict["Sample"]["Geometry"]["Radius"] - cond2 = type(final_dict["Sample"]["Geometry"]["Radius"]) == int - cond3 = type(final_dict["Sample"]["Geometry"]["Radius"]) == float + cond2 = final_dict["Sample"]["Geometry"]["Radius"].isinstance(int) + cond3 = final_dict["Sample"]["Geometry"]["Radius"].isinstance(float) if not (cond1 and (cond2 or cond3)): log_error(2, '["Sample"]["Geometry"]["Radius"]') return False cond1 = final_dict["Sample"]["Geometry"]["Height"] - cond2 = type(final_dict["Sample"]["Geometry"]["Height"]) == int - cond3 = type(final_dict["Sample"]["Geometry"]["Height"]) == float + cond2 = final_dict["Sample"]["Geometry"]["Height"].isinstance(int) + cond3 = final_dict["Sample"]["Geometry"]["Height"].isinstance(float) if not (cond1 and (cond2 or cond3)): log_error(2, '["Sample"]["Geometry"]["Height"]') return False @@ -883,7 +883,7 @@ def final_validator(final_dict): # Check 'Normalization' entry. if "Runs" in final_dict["Normalization"]: - if type(final_dict["Normalization"]["Runs"]) == str: + if final_dict["Normalization"]["Runs"].isinstance(str): run_num_tmp = re.split("-|,| ", final_dict["Normalization"]["Runs"]) if not check_all_decimal(run_num_tmp): log_error(2, '["Normalization"]["Run"]') @@ -896,7 +896,7 @@ def final_validator(final_dict): return False if "Background" in final_dict["Normalization"]: if "Runs" in final_dict["Normalization"]["Background"]: - if type(final_dict["Normalization"]["Background"]["Runs"]) == str: + if final_dict["Normalization"]["Background"]["Runs"].isinstance(str): bkg_run_num = re.split("-|,| ", final_dict["Normalization"]["Background"]["Runs"]) if not check_all_decimal(bkg_run_num): log_error(2, '["Normalization"]["Background"]["Runs"]') @@ -911,15 +911,15 @@ def final_validator(final_dict): log_error(1, '["Normalization"]["Background"]') return False if "Material" in final_dict["Normalization"]: - if not type(final_dict["Normalization"]["Material"]) == str: + if not final_dict["Normalization"]["Material"].isinstance(str): log_error(2, '["Normalization"]["Material"]') return False else: log_error(1, '["Normalization"]["Material"]') if "MassDensity" in final_dict["Normalization"]: cond1 = final_dict["Normalization"]["MassDensity"] - cond2 = type(final_dict["Normalization"]["MassDensity"]) == int - cond3 = type(final_dict["Normalization"]["MassDensity"]) == float + cond2 = final_dict["Normalization"]["MassDensity"].isinstance(int) + cond3 = final_dict["Normalization"]["MassDensity"].isinstance(float) if not (cond1 and (cond2 or cond3)): log_error(2, '["Normalization"]["MassDensity"]') return False @@ -927,8 +927,8 @@ def final_validator(final_dict): log_error(1, '["Normalization"]["MassDensity"]') if "PackingFraction" in final_dict["Normalization"]: cond1 = final_dict["Normalization"]["PackingFraction"] - cond2 = type(final_dict["Normalization"]["PackingFraction"]) == int - cond3 = type(final_dict["Normalization"]["PackingFraction"]) == float + cond2 = final_dict["Normalization"]["PackingFraction"].isinstance(int) + cond3 = final_dict["Normalization"]["PackingFraction"].isinstance(float) if not (cond1 and (cond2 or cond3)): log_error(2, '["Normalization"]["PackingFraction"]') return False @@ -937,14 +937,14 @@ def final_validator(final_dict): if "Geometry" in final_dict["Normalization"]: if "Radius" in final_dict["Normalization"]["Geometry"] and "Height" in final_dict["Normalization"]["Geometry"]: cond1 = final_dict["Normalization"]["Geometry"]["Radius"] - cond2 = type(final_dict["Normalization"]["Geometry"]["Radius"]) == int - cond3 = type(final_dict["Normalization"]["Geometry"]["Radius"]) == float + cond2 = final_dict["Normalization"]["Geometry"]["Radius"].isinstance(int) + cond3 = final_dict["Normalization"]["Geometry"]["Radius"].isinstance(float) if not (cond1 and (cond2 or cond3)): log_error(2, '["Normalization"]["Geometry"]["Radius"]') return False cond1 = final_dict["Normalization"]["Geometry"]["Height"] - cond2 = type(final_dict["Normalization"]["Geometry"]["Height"]) == int - cond3 = type(final_dict["Normalization"]["Geometry"]["Height"]) == float + cond2 = final_dict["Normalization"]["Geometry"]["Height"].isinstance(int) + cond3 = final_dict["Normalization"]["Geometry"]["Height"].isinstance(float) if not (cond1 and (cond2 or cond3)): log_error(2, '["Normalization"]["Geometry"]["Height"]') return False @@ -960,7 +960,7 @@ def final_validator(final_dict): # Check "Merging" entry if "QBinning" in final_dict["Merging"]: - if type(final_dict["Merging"]["QBinning"]) == list: + if final_dict["Merging"]["QBinning"].isinstance(list): cond1 = len(final_dict["Merging"]["QBinning"]) == 3 cond2 = check_all_number(final_dict["Merging"]["QBinning"]) if not (cond1 and cond2): diff --git a/addie/processing/mantid/master_table/master_table_loader.py b/addie/processing/mantid/master_table/master_table_loader.py index b50f40b1..81e3aaee 100755 --- a/addie/processing/mantid/master_table/master_table_loader.py +++ b/addie/processing/mantid/master_table/master_table_loader.py @@ -376,7 +376,7 @@ def load(self): if "AbsMSParameters" in _source_row_entry["Sample"]: ele_size_val = _source_row_entry["Sample"]["AbsMSParameters"]["ElementSize"] - if type(ele_size_val) == list: + if ele_size_val.isinstance(list): ele_size_val = ",".join([str(item) for item in ele_size_val]) else: ele_size_val = str(ele_size_val) diff --git a/tests/utilities/test_customtreeview.py b/tests/utilities/test_customtreeview.py index 7427cadd..d76b1ea9 100644 --- a/tests/utilities/test_customtreeview.py +++ b/tests/utilities/test_customtreeview.py @@ -51,4 +51,4 @@ def test_get_selected_items(qtbot, custom_tree_view): items = custom_tree_view.get_selected_items() items_list = [str(item.text()) for item in items] assert items_list == [main_item] - assert type(items) == list + assert items.isinstance(list)