mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-15 10:18:31 +00:00
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 <calibrain@l4n.xyz>
This commit is contained in:
1 parent
e83bab9337
commit
82c8c91c8b
2 files changed
+8
-4
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user