Skip to content

Let fail_at/fail_after scopes be inspected before entering - #3601

Closed
tony1233200 wants to merge 1 commit into
python-trio:mainfrom
tony1233200:fix/3090-fail-scope-inspection
Closed

tony1233200 wants to merge 1 commit into
python-trio:mainfrom
tony1233200:fix/3090-fail-scope-inspection

Conversation

@tony1233200

Copy link
Copy Markdown

Summary

Fixes #3090, using the first approach the issue proposes: fail_at and fail_after now return a small wrapper around the underlying CancelScope instead of a generator-based context manager.

  • Attribute reads and writes on the returned object pass through to the wrapped scope, so fail_at(5).deadline and fail_after(5).relative_deadline work before entering, and a modified relative_deadline takes 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 raises TooSlowError if 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_entering now 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 only src/trio/_timeouts.py makes the new test fail again (mutation check). ruff check and ruff format --check are clean on the touched files. Note: test_exports.py shows 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.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.97450%. Comparing base (c327959) to head (5eb2b1a).

Files with missing lines Patch % Lines
src/trio/_timeouts.py 77.27273% 3 Missing and 2 partials ⚠️
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     
Files with missing lines Coverage Δ
src/trio/_tests/test_timeouts.py 100.00000% <100.00000%> (ø)
src/trio/_timeouts.py 90.00000% <77.27273%> (-10.00000%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@A5rocks A5rocks closed this Nov 19, 2026
@CoolCat467 CoolCat467 added the LLM Slop Entirely generated by a large language model with little or no human oversight label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM Slop Entirely generated by a large language model with little or no human oversight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable inspection of fail_at/fail_after attributes

3 participants