From 2f740752f0d18ab68a9920f636b6ccec3f73811c Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 16 Dec 2024 16:22:41 -0500 Subject: [PATCH] Yield error if attempts_allowed is not int MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For that exception we did get logged: ❯ grep Assertion /home/yoh/.local/state/dandi-cli/log/2024.12.16* /home/yoh/.local/state/dandi-cli/log/2024.12.16-15.24.12Z-119733.log:AssertionError: attempts_allowed_or_not is None of type which makes little sense (besides some thread unsafe handling or None becoming bool(True))). To overcome and avoid need for assert, just fold that condition directly into "if" statement. --- dandi/download.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/dandi/download.py b/dandi/download.py index 497fdaad7..ca94ae7db 100644 --- a/dandi/download.py +++ b/dandi/download.py @@ -803,14 +803,9 @@ def _download_file( attempts_allowed=attempts_allowed, downloaded_in_attempt=downloaded_in_attempt, ) - if not attempts_allowed: + if not isinstance(attempts_allowed_or_not, int) or not attempts_allowed: yield {"status": "error", "message": str(exc)} return - # for clear(er) typing, here we get only with int - assert isinstance(attempts_allowed_or_not, int), ( - f"attempts_allowed_or_not is {attempts_allowed_or_not!r} " - f"of type {type(attempts_allowed_or_not)}" - ) attempts_allowed = attempts_allowed_or_not else: lgr.warning("downloader logic: We should not be here!")