Commit 7341924
Document the retry loop invariant on the final raise last_error
The `# type: ignore[misc]` on the final `raise last_error` silenced a
real mypy complaint (`last_error` is typed `Exception | None`) without
explaining why the raise is safe. The reason is a loop invariant: the
only non-`return` way out of the loop is the `break` on the final
attempt, which runs immediately after `last_error = e`, and the guard
at line 33 rejects `max_attempts < 1`. Expand the comment so the next
reader can verify the claim without tracing the function.
Also add a test that exercises the one-attempt edge case — `range(1)`
is the boundary where the loop body must set `last_error` and
immediately break on the first iteration.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 27f7aa3 commit 7341924
2 files changed
+20
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
56 | 59 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
50 | 67 | | |
51 | 68 | | |
52 | 69 | | |
| |||
0 commit comments