Repository navigation
Let fail_at/fail_after scopes be inspected before entering - #3601
Closed
tony1233200 wants to merge 1 commit into
Closed
tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3601 +/- ##
====================================================
- Coverage 100.00000% 99.97450% -0.02550%
====================================================
Files 128 128
Lines 19586 19607 +21
Branches 1334 1335 +1
====================================================
+ Hits 19586 19602 +16
- Misses 0 3 +3
- Partials 0 2 +2
🚀 New features to boost your workflow:
|
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.
Summary
Fixes #3090, using the first approach the issue proposes:
fail_atandfail_afternow return a small wrapper around the underlyingCancelScopeinstead of a generator-based context manager.fail_at(5).deadlineandfail_after(5).relative_deadlinework before entering, and a modifiedrelative_deadlinetakes effect on entry.__enter__enters the wrapped scope and returns the scope itself, so code inside the block sees exactly what it saw before.__exit__delegates to the wrapped scope and raisesTooSlowErrorif the scope caught a cancellation, matching the previous behaviour in the expiry, shielded, clean-exit and body-exception cases (each verified by hand as well as by the existing tests).The previously xfail-marked
test_fail_access_before_enteringnow passes with the marker removed, and is extended to cover attribute writes before entering. A newsfragment is included.Tests
pytest src/trio/_tests/test_timeouts.py: 7 passed, 5 skipped. Reverting onlysrc/trio/_timeouts.pymakes the new test fail again (mutation check).ruff checkandruff format --checkare clean on the touched files. Note:test_exports.pyshows 14 failures in this sandbox both with and without this change (missing jedi/mypy tooling in the local venv), so those are environmental, not from this PR.Disclosure: this patch was drafted with an AI coding assistant (Claude) and reviewed by me; the design follows the approach sketched in the issue itself.