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

add deprecation warning for specifying strict_exception_groups=False #2941

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from .. import _core
from .._abc import Clock, Instrument
from .._deprecate import warn_deprecated
from .._util import NoPublicConstructor, coroutine_or_error, final
from ._asyncgens import AsyncGenerators
from ._concat_tb import concat_tb
Expand Down Expand Up @@ -997,6 +998,15 @@ def open_nursery(
and ultimately removed in a future version of Trio.

"""
# only warn if explicitly set to False, not if we get it from the global context.
if strict_exception_groups is False:
warn_deprecated(
"open_nursery(strict_exception_groups=False)",
version="0.24.1",
issue=2929,
instead="Use the default value of True and rewrite exception handlers to handle ExceptionGroups",
)

if strict_exception_groups is None:
strict_exception_groups = GLOBAL_RUN_CONTEXT.runner.strict_exception_groups

Expand Down Expand Up @@ -2244,6 +2254,13 @@ def run(
propagates it.

"""
if strict_exception_groups is False:
warn_deprecated(
"trio.run(..., strict_exception_groups=False)",
version="0.24.1",
issue=2929,
instead="the default value of True and rewrite exception handlers to handle ExceptionGroups",
Zac-HD marked this conversation as resolved.
Show resolved Hide resolved
)

__tracebackhide__ = True

Expand Down Expand Up @@ -2350,6 +2367,14 @@ def my_done_callback(run_outcome):
For the meaning of other arguments, see `trio.run`.

"""
if strict_exception_groups is False:
warn_deprecated(
"trio.start_guest_run(..., strict_exception_groups=False)",
version="0.24.1",
issue=2929,
instead="Use the default value of True and rewrite exception handlers to handle ExceptionGroups",
)

runner = setup_runner(
clock,
instruments,
Expand Down
9 changes: 9 additions & 0 deletions src/trio/_core/_tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,9 @@ def _create_kwargs(strictness: bool | None) -> dict[str, bool]:
return {"strict_exception_groups": strictness}


@pytest.mark.filterwarnings(
"ignore:.*strict_exception_groups=False:trio.TrioDeprecationWarning"
)
@pytest.mark.parametrize("run_strict", [True, False, None])
@pytest.mark.parametrize("open_nursery_strict", [True, False, None])
@pytest.mark.parametrize("multiple_exceptions", [True, False])
Expand Down Expand Up @@ -2591,6 +2594,9 @@ def run_main() -> None:
run_main()


@pytest.mark.filterwarnings(
"ignore:.*strict_exception_groups=False:trio.TrioDeprecationWarning"
)
@pytest.mark.parametrize("strict", [True, False, None])
async def test_nursery_collapse(strict: bool | None) -> None:
"""
Expand Down Expand Up @@ -2630,6 +2636,9 @@ async def test_cancel_scope_no_cancellederror() -> None:
assert not scope.cancelled_caught


@pytest.mark.filterwarnings(
"ignore:.*strict_exception_groups=False:trio.TrioDeprecationWarning"
)
@pytest.mark.parametrize("run_strict", [False, True])
@pytest.mark.parametrize("start_raiser_strict", [False, True, None])
@pytest.mark.parametrize("raise_after_started", [False, True])
Expand Down
61 changes: 61 additions & 0 deletions src/trio/_tests/test_deprecate_strict_exception_groups_false.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from typing import Awaitable, Callable

import pytest

import trio


async def test_deprecation_warning_open_nursery() -> None:
with pytest.warns(
trio.TrioDeprecationWarning, match="strict_exception_groups=False"
) as record:
async with trio.open_nursery(strict_exception_groups=False):
...
assert len(record) == 1
async with trio.open_nursery(strict_exception_groups=True):
...
async with trio.open_nursery():
...


def test_deprecation_warning_run() -> None:
async def foo() -> None: ...

async def foo_nursery() -> None:
# this should not raise a warning, even if it's implied loose
async with trio.open_nursery():
...

async def foo_loose_nursery() -> None:
# this should raise a warning, even if specifying the parameter is redundant
async with trio.open_nursery(strict_exception_groups=False):
...

def helper(fun: Callable[..., Awaitable[None]], num: int) -> None:
with pytest.warns(
trio.TrioDeprecationWarning, match="strict_exception_groups=False"
) as record:
trio.run(fun, strict_exception_groups=False)
assert len(record) == num

helper(foo, 1)
helper(foo_nursery, 1)
helper(foo_loose_nursery, 2)


def test_deprecation_warning_start_guest_run() -> None:
# "The simplest possible "host" loop."
from .._core._tests.test_guest_mode import trivial_guest_run

async def trio_return(in_host: object) -> str:
await trio.lowlevel.checkpoint()
return "ok"

with pytest.warns(
trio.TrioDeprecationWarning, match="strict_exception_groups=False"
) as record:
trivial_guest_run(
trio_return,
strict_exception_groups=False,
)
assert len(record) == 1
3 changes: 0 additions & 3 deletions src/trio/_tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,6 @@ async def do_stuff() -> None:
with RaisesGroup(RaisesGroup(Matcher(ValueError, "^foo$"))):
_core.run(do_stuff, strict_exception_groups=True)

with pytest.raises(ValueError, match="^foo$"):
_core.run(do_stuff, strict_exception_groups=False)


async def test_warn_on_failed_cancel_terminate(monkeypatch: pytest.MonkeyPatch) -> None:
original_terminate = Process.terminate
Expand Down
Loading