Share task timing option parsing#18
Conversation
There was a problem hiding this comment.
PR Review
PR: Share task timing option parsing
Important
Verdict: Request changes - 1 actionable finding, highest severity P1.
Findings (1)
duration_from_seconds converts 0 to None
src/cashet/_client_base.py:59
The function uses truthiness (if seconds) to decide whether to return a timedelta. Passing 0 or 0.0 evaluates to False, so the function returns None instead of timedelta(0). This silently changes the behavior from the previous explicit None check, where a zero timeout or TTL was preserved. A zero timeout can be meaningful (e.g., no delay or immediate expiration), so collapsing it to None is incorrect.
How To Recheck
Reply @ds-review recheck under the relevant inline finding after pushing a fix.
|
|
||
|
|
||
| def duration_from_seconds(seconds: int | float | None) -> timedelta | None: | ||
| return timedelta(seconds=seconds) if seconds else None |
There was a problem hiding this comment.
duration_from_seconds converts 0 to None
The function uses truthiness (if seconds) to decide whether to return a timedelta. Passing 0 or 0.0 evaluates to False, so the function returns None instead of timedelta(0). This silently changes the behavior from the previous explicit None check, where a zero timeout or TTL was preserved. A zero timeout can be meaningful (e.g., no delay or immediate expiration), so collapsing it to None is incorrect.
| return timedelta(seconds=seconds) if seconds else None | |
| return timedelta(seconds=seconds) if seconds is not None else None |
There was a problem hiding this comment.
Recheck: resolved. The duration_from_seconds function now uses if seconds is not None instead of truthiness, so passing 0 returns timedelta(0) instead of None.
Summary
timedeltavaluesValidation
uv run ruff check src/ tests/uv run pyright src/uv run pytest tests/ -v