From d13452850c00801e1077c9c64522e3584da5f27d Mon Sep 17 00:00:00 2001 From: Jah-yee <166608075+Jah-yee@users.noreply.github.com> Date: Fri, 2 Oct 2026 19:21:53 +0800 Subject: [PATCH] fix: check for None before dividing completion times by 3600 Null completion time values (e.g. comp_main: null) raise TypeError when divided by 3600. The comment says 'Calculate only if value is not None' but the code only checks for key existence, not null values. Fix: add 'is not None' check to all 6 completion time fields. --- howlongtobeatpy/howlongtobeatpy/JSONResultParser.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/howlongtobeatpy/howlongtobeatpy/JSONResultParser.py b/howlongtobeatpy/howlongtobeatpy/JSONResultParser.py index 544a704..255abee 100644 --- a/howlongtobeatpy/howlongtobeatpy/JSONResultParser.py +++ b/howlongtobeatpy/howlongtobeatpy/JSONResultParser.py @@ -73,17 +73,17 @@ def parse_json_element(self, input_game_element): current_entry.json_content = input_game_element # Add a few times elements as help for the user # Calculate only if value is not None - if "comp_main" in input_game_element: + if "comp_main" in input_game_element and input_game_element.get("comp_main") is not None: current_entry.main_story = round(input_game_element.get("comp_main") / 3600, 2) - if "comp_plus" in input_game_element: + if "comp_plus" in input_game_element and input_game_element.get("comp_plus") is not None: current_entry.main_extra = round(input_game_element.get("comp_plus") / 3600, 2) - if "comp_100" in input_game_element: + if "comp_100" in input_game_element and input_game_element.get("comp_100") is not None: current_entry.completionist = round(input_game_element.get("comp_100") / 3600, 2) - if "comp_all" in input_game_element: + if "comp_all" in input_game_element and input_game_element.get("comp_all") is not None: current_entry.all_styles = round(input_game_element.get("comp_all") / 3600, 2) - if "invested_co" in input_game_element: + if "invested_co" in input_game_element and input_game_element.get("invested_co") is not None: current_entry.coop_time = round(input_game_element.get("invested_co") / 3600, 2) - if "invested_mp" in input_game_element: + if "invested_mp" in input_game_element and input_game_element.get("invested_mp") is not None: current_entry.mp_time = round(input_game_element.get("invested_mp") / 3600, 2) # Add complexity booleans current_entry.complexity_lvl_combine = bool(input_game_element.get("comp_lvl_combine", 0))