diff --git a/shelfmark/download/clients/base_handler.py b/shelfmark/download/clients/base_handler.py index 27e9a8c4..2d847e21 100644 --- a/shelfmark/download/clients/base_handler.py +++ b/shelfmark/download/clients/base_handler.py @@ -273,10 +273,12 @@ class ExternalClientHandler(DownloadHandler, ABC): def _stall_window_seconds() -> float: """How long a torrent may go without progress, from the user's setting (seconds).""" raw = config.get(STALL_TIMEOUT_SETTING, STALL_TIMEOUT_DEFAULT_MINUTES) - try: - minutes = float(raw) # pyright: ignore[reportArgumentType] - except TypeError, ValueError: - minutes = float(STALL_TIMEOUT_DEFAULT_MINUTES) + minutes = float(STALL_TIMEOUT_DEFAULT_MINUTES) + if isinstance(raw, (int, float, str)): + try: + minutes = float(raw) + except ValueError: + minutes = float(STALL_TIMEOUT_DEFAULT_MINUTES) if not math.isfinite(minutes): minutes = float(STALL_TIMEOUT_DEFAULT_MINUTES) minutes = min(max(minutes, STALL_TIMEOUT_MIN_MINUTES), STALL_TIMEOUT_MAX_MINUTES) diff --git a/tests/download/test_torrent_queue_stall.py b/tests/download/test_torrent_queue_stall.py index a7fba9a9..f4ab4934 100644 --- a/tests/download/test_torrent_queue_stall.py +++ b/tests/download/test_torrent_queue_stall.py @@ -229,6 +229,8 @@ def test_a_value_above_the_maximum_is_capped() -> None: (500, 3600.0), # above the maximum ("soon", 900.0), # not a number: the default ("", 900.0), + (None, 900.0), + ([5], 900.0), (float("nan"), 900.0), (float("inf"), 900.0), ],