Make sleep() name its own parameter when given NaN - #3511
Open
dylanpulver wants to merge 2 commits into
Open
Conversation
sleep() validated seconds < 0 itself but let NaN reach the deadline check in _core, so it raised "deadline must not be NaN" for a value the caller passed as seconds. Its docstring already documents ValueError for NaN. move_on_after duplicates this validation on purpose, with a comment saying it is to get the parameter name right; sleep never did. The existing test could not catch it: its pattern was an alternation over both spellings, so either message passed. Each case now pins the message for the parameter that function actually takes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3511 +/- ##
===============================================
Coverage 100.00000% 100.00000%
===============================================
Files 128 128
Lines 19454 19457 +3
Branches 1321 1322 +1
===============================================
+ Hits 19454 19457 +3
🚀 New features to boost your workflow:
|
Member
|
this looks like a good fix, but CI is failing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
trio.sleep(float("nan"))raisesValueError: deadline must not be NaN, naming a value the caller never passed.sleeptakesseconds.sleepvalidatesseconds < 0itself but lets NaN through to the deadline check in_core, which is where the wording comes from. Its docstring already promises the error:move_on_afterduplicates the same two checks deliberately, with the comment# duplicate validation logic to have the correct parameter name.sleepnever got the same treatment. This adds the missing NaN check there, so all nine paths now name the parameter they actually take:secondsforsleep,fail_afterandmove_on_after,deadlineforsleep_until,fail_atandmove_on_at.The existing
test_timeouts_raise_value_errorcould not have caught this. Its pattern was^(deadline|seconds) must (not )*be (non-negative|NaN)$, an alternation accepting either spelling for every function, so both the old and new messages pass it. Each case now pins the exact message for its own parameter; reverting_timeouts.pyfails the test with- deadline must not be NaN/+secondsmust not be NaN.Context: #2493 reported that
sleep(nan)slept forever and was fixed at the deadline level, which is why the value is rejected today but under the wrong name.159 pass across
test_timeouts.pyand_core/_tests/test_run.py.🤖 Generated with Claude Code
https://claude.ai/code/session_011M5uTyCU4WcNTsPvGrErDo