Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usage of strict_exception_groups=False in Nursery.start #2938

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Jan 29, 2024

In preparation for eventual deprecation of strict_exception_groups=False (https://github.com/jakkdl/trio/tree/deprecate_exceptiongroups_false) we probably shouldn't rely on it ourselves in the internal code.

#2611 - the original issue where errors raised before task_status.started() got double-wrapped
#1599 - for why the old nursery can have multiple tasks.
#2844 - the regression error that occured after my initial fix for #2611 in #2826

Fairly straightforward implementation, other than perhaps exactly what to raise when multiple exceptions do occur. The main code that tests this is test_trio_run_strict_before_started, I added the new test after it only to trigger the case where multiple exceptions do pop up in the old nursery.

@jakkdl jakkdl requested review from oremanj and Zac-HD January 29, 2024 15:06
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7cb15ea) 99.64% compared to head (03fee26) 99.64%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2938   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files         116      116           
  Lines       17506    17523   +17     
  Branches     3148     3151    +3     
=======================================
+ Hits        17444    17461   +17     
  Misses         43       43           
  Partials       19       19           
Files Coverage Δ
src/trio/_core/_run.py 99.66% <100.00%> (+<0.01%) ⬆️
src/trio/_core/_tests/test_run.py 100.00% <100.00%> (ø)

# TODO: give a deprecationwarning instead?
raise TrioInternalError(
"internal nursery should not have multiple tasks"
) from exc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked how one of the linked PRs proposed warning in .start_soon for that internal nursery (re: todo)

except BaseExceptionGroup as exc:
if len(exc.exceptions) == 1:
raise exc.exceptions[0] from None
# TODO: give a deprecationwarning instead?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think making this an internal error immediately is fine - it's possible to do this, but it's never been something we documented or that we think is reasonable to have done for some reason.

@jakkdl
Copy link
Member Author

jakkdl commented Jan 30, 2024

sounds like we're settling on internalerror, and leaving any eventual warning for #1600 or similar.
removed the comment and expanded the error message to make it clearer for the user that it might be their fault.

@Zac-HD
Copy link
Member

Zac-HD commented Jan 31, 2024

Very nice! Merging now 😁

@Zac-HD Zac-HD merged commit b6a31d7 into python-trio:master Jan 31, 2024
29 checks passed
@jakkdl jakkdl deleted the strict_internal_nursery_in_start branch February 5, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants