From 82c8c91c8bcf8574df5d14a343680c23c339e8e8 Mon Sep 17 00:00:00 2001 From: splitsec2 <35583321+splitsec2@users.noreply.github.com> Date: Tue, 20 Oct 2026 21:28:42 -0600 Subject: [PATCH] refactor(clients): read the stall window with a type check instead of a pyright ignore (#1498) The only `pyright: ignore[reportArgumentType]` in `shelfmark/` is one I added in #1426, and I was being lazy when I did. I hit the same error on another PR and replaced the ignore there with a real check, so this does the same for the original. `_stall_window_seconds` reads the setting as an `object`. It now narrows to int, float or str before calling `float()`, and a bad string falls back to the default as before. A non-numeric value of another type (None, a list) falls back to the default too, which used to happen through a `TypeError`. No behaviour change. The existing range test still passes and I added `None` and a list to it. basedpyright is at 0 errors, ruff is clean and the backend suite passes. Co-authored-by: CaliBrain --- shelfmark/download/clients/base_handler.py | 10 ++++++---- tests/download/test_torrent_queue_stall.py | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) 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), ],