Skip to content

Commit

Permalink
Merge branch 'main' into avoid-refcycles-in-run-exc
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored Dec 24, 2024
2 parents 7c0fb4c + 3260974 commit 174bd07
Show file tree
Hide file tree
Showing 27 changed files with 95 additions and 73 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/autodeps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: true # credentials are needed to push commits
- name: Setup python
uses: actions/setup-python@v5
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/check-newsfragment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Check newsfragments
run: |
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:

- name: Grab the source from Git
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Get the dist version
id: dist-version
Expand All @@ -50,10 +52,11 @@ jobs:
- name: Set the expected dist artifact names
id: artifact-name
run: |
echo 'sdist=${{ env.dist-name }}-*.tar.gz' >> "${GITHUB_OUTPUT}"
echo 'wheel=${{
env.dist-name
}}-*-py3-none-any.whl' >> "${GITHUB_OUTPUT}"
echo "sdist=${DIST_NAME}-${VERSION}.tar.gz" >> "${GITHUB_OUTPUT}"
echo "wheel=${DIST_NAME}-${VERSION}-py3-none-any.whl" >> "${GITHUB_OUTPUT}"
env:
DIST_NAME: ${{ env.dist-name }}
VERSION: ${{ steps.dist-version.outputs.version }}

- name: Install build
run: python -Im pip install build
Expand All @@ -63,8 +66,11 @@ jobs:
- name: Verify that the artifacts with expected names got created
run: >-
ls -1
dist/${{ steps.artifact-name.outputs.sdist }}
dist/${{ steps.artifact-name.outputs.wheel }}
dist/${SDIST}
dist/${WHEEL}
env:
SDIST: ${{ steps.artifact-name.outputs.sdist }}
WHEEL: ${{ steps.artifact-name.outputs.wheel }}
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -99,6 +105,7 @@ jobs:
uses: actions/checkout@v4
with:
path: git-src
persist-credentials: false
- name: >-
Smoke-test: install test requirements from the Git repo
Expand Down Expand Up @@ -260,6 +267,8 @@ jobs:
- name: Grab the source from Git
if: matrix.check_formatting == '1'
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup python
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.9"
Expand Down
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
rev: v0.8.4
hooks:
- id: ruff
types: [file]
Expand All @@ -36,6 +36,10 @@ repos:
rev: v1.0.0
hooks:
- id: sphinx-lint
- repo: https://github.com/woodruffw/zizmor-pre-commit
rev: v0.10.0
hooks:
- id: zizmor
- repo: local
hooks:
- id: regenerate-files
Expand Down
2 changes: 1 addition & 1 deletion src/trio/_core/_tests/test_instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def after_run(self) -> NoReturn:
raise ValueError("oops")

async def main() -> None:
with pytest.raises(ValueError, match="^oops$"):
with pytest.raises(ValueError, match=r"^oops$"):
_core.add_instrument(EvilInstrument())

# Make sure the instrument is fully removed from the per-method lists
Expand Down
4 changes: 2 additions & 2 deletions src/trio/_core/_tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ async def reset_check() -> None:
t2.reset(token2)
assert t2.get() == "dogfish"

with pytest.raises(ValueError, match="^token has already been used$"):
with pytest.raises(ValueError, match=r"^token has already been used$"):
t2.reset(token2)

token3 = t3.set("basculin")
assert t3.get() == "basculin"

with pytest.raises(ValueError, match="^token is not for us$"):
with pytest.raises(ValueError, match=r"^token is not for us$"):
t1.reset(token3)

run(reset_check)
Expand Down
4 changes: 2 additions & 2 deletions src/trio/_core/_tests/test_mock_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def test_mock_clock() -> None:
assert c.current_time() == 0
c.jump(1.2)
assert c.current_time() == 1.2
with pytest.raises(ValueError, match="^time can't go backwards$"):
with pytest.raises(ValueError, match=r"^time can't go backwards$"):
c.jump(-1)
assert c.current_time() == 1.2
assert c.deadline_to_sleep_time(1.1) == 0
assert c.deadline_to_sleep_time(1.2) == 0
assert c.deadline_to_sleep_time(1.3) > 999999

with pytest.raises(ValueError, match="^rate must be >= 0$"):
with pytest.raises(ValueError, match=r"^rate must be >= 0$"):
c.rate = -1
assert c.rate == 0

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_core/_tests/test_parking_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ async def test_parking_lot_breaker_register_exited_task() -> None:
# trying to register an exited task as lot breaker errors
with pytest.raises(
trio.BrokenResourceError,
match="^Attempted to add already exited task as lot breaker.$",
match=r"^Attempted to add already exited task as lot breaker.$",
):
add_parking_lot_breaker(child_task, lot)

Expand Down
30 changes: 15 additions & 15 deletions src/trio/_core/_tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_initial_task_error() -> None:
async def main(x: object) -> NoReturn:
raise ValueError(x)

with pytest.raises(ValueError, match="^17$") as excinfo:
with pytest.raises(ValueError, match=r"^17$") as excinfo:
_core.run(main, 17)
assert excinfo.value.args == (17,)

Expand Down Expand Up @@ -246,7 +246,7 @@ async def child2() -> None:
t2 = _core.current_task()
_core.reschedule(not_none(t1), outcome.Value(0))
print("child2 sleep")
with pytest.raises(ValueError, match="^error message$"):
with pytest.raises(ValueError, match=r"^error message$"):
await sleep_forever()
print("child2 successful exit")

Expand Down Expand Up @@ -369,26 +369,26 @@ async def test_cancel_scope_repr(mock_clock: _core.MockClock) -> None:
async def test_cancel_scope_validation() -> None:
with pytest.raises(
ValueError,
match="^Cannot specify both a deadline and a relative deadline$",
match=r"^Cannot specify both a deadline and a relative deadline$",
):
_core.CancelScope(deadline=7, relative_deadline=3)

with pytest.raises(ValueError, match="^deadline must not be NaN$"):
with pytest.raises(ValueError, match=r"^deadline must not be NaN$"):
_core.CancelScope(deadline=nan)
with pytest.raises(ValueError, match="^relative deadline must not be NaN$"):
with pytest.raises(ValueError, match=r"^relative deadline must not be NaN$"):
_core.CancelScope(relative_deadline=nan)

with pytest.raises(ValueError, match="^timeout must be non-negative$"):
with pytest.raises(ValueError, match=r"^timeout must be non-negative$"):
_core.CancelScope(relative_deadline=-3)

scope = _core.CancelScope()

with pytest.raises(ValueError, match="^deadline must not be NaN$"):
with pytest.raises(ValueError, match=r"^deadline must not be NaN$"):
scope.deadline = nan
with pytest.raises(ValueError, match="^relative deadline must not be NaN$"):
with pytest.raises(ValueError, match=r"^relative deadline must not be NaN$"):
scope.relative_deadline = nan

with pytest.raises(ValueError, match="^relative deadline must be non-negative$"):
with pytest.raises(ValueError, match=r"^relative deadline must be non-negative$"):
scope.relative_deadline = -3
scope.relative_deadline = 5
assert scope.relative_deadline == 5
Expand Down Expand Up @@ -1063,7 +1063,7 @@ async def child1() -> None:
async with seq(0):
pass # we don't yield until seq(2) below
record.append("child1 raise")
with pytest.raises(ValueError, match="^child1$") as excinfo:
with pytest.raises(ValueError, match=r"^child1$") as excinfo:
try:
raise ValueError("child1")
except ValueError:
Expand Down Expand Up @@ -1360,7 +1360,7 @@ async def main() -> None:
token.run_sync_soon(lambda: record.append("sync-cb"))
raise ValueError("error text")

with pytest.raises(ValueError, match="^error text$"):
with pytest.raises(ValueError, match=r"^error text$"):
_core.run(main)

assert record == ["sync-cb"]
Expand Down Expand Up @@ -1724,12 +1724,12 @@ async def async_gen(arg: T) -> AsyncGenerator[T, None]: # pragma: no cover
# different ways
with pytest.raises(
TypeError,
match="^Trio was expecting an async function, but instead it got a coroutine object <.*>",
match=r"^Trio was expecting an async function, but instead it got a coroutine object <.*>",
):
bad_call_run(f()) # type: ignore[arg-type]
with pytest.raises(
TypeError,
match="expected an async function but got an async generator",
match=r"expected an async function but got an async generator",
):
bad_call_run(async_gen, 0) # type: ignore

Expand Down Expand Up @@ -2655,7 +2655,7 @@ def run_main() -> None:
# mypy doesn't like kwarg magic
_core.run(main, **_create_kwargs(run_strict)) # type: ignore[arg-type]

matcher = Matcher(RuntimeError, "^test error$")
matcher = Matcher(RuntimeError, r"^test error$")

if multiple_exceptions:
with RaisesGroup(matcher, matcher):
Expand All @@ -2666,7 +2666,7 @@ def run_main() -> None:
with RaisesGroup(matcher):
run_main()
else:
with pytest.raises(RuntimeError, match="^test error$"):
with pytest.raises(RuntimeError, match=r"^test error$"):
run_main()


Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
async def test_channel() -> None:
with pytest.raises(TypeError):
open_memory_channel(1.0)
with pytest.raises(ValueError, match="^max_buffer_size must be >= 0$"):
with pytest.raises(ValueError, match=r"^max_buffer_size must be >= 0$"):
open_memory_channel(-1)

s, r = open_memory_channel[Union[int, str, None]](2)
Expand Down
4 changes: 2 additions & 2 deletions src/trio/_tests/test_dtls.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def test_smoke(ipv6: bool) -> None:

with pytest.raises(
ValueError,
match="^openssl doesn't support sending empty DTLS packets$",
match=r"^openssl doesn't support sending empty DTLS packets$",
):
await client_channel.send(b"")

Expand Down Expand Up @@ -299,7 +299,7 @@ async def null_handler(_: object) -> None: # pragma: no cover

async def test_dtls_over_dgram_only() -> None:
with trio.socket.socket() as s:
with pytest.raises(ValueError, match="^DTLS requires a SOCK_DGRAM socket$"):
with pytest.raises(ValueError, match=r"^DTLS requires a SOCK_DGRAM socket$"):
DTLSEndpoint(s)


Expand Down
26 changes: 15 additions & 11 deletions src/trio/_tests/test_fakenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def test_recv_methods() -> None:
assert await s1.sendto(b"ghi", s2.getsockname()) == 3
buf = bytearray(10)

with pytest.raises(NotImplementedError, match="^partial recvfrom_into$"):
with pytest.raises(NotImplementedError, match=r"^partial recvfrom_into$"):
(nbytes, addr) = await s2.recvfrom_into(buf, nbytes=2)

(nbytes, addr) = await s2.recvfrom_into(buf)
Expand All @@ -121,14 +121,18 @@ async def test_recv_methods() -> None:
with pytest.raises(OSError, match=ENOTCONN_MSG) as exc:
await s2.send(b"mno")
assert exc.value.errno == errno.ENOTCONN
with pytest.raises(NotImplementedError, match="^FakeNet send flags must be 0, not"):
with pytest.raises(
NotImplementedError, match=r"^FakeNet send flags must be 0, not"
):
await s2.send(b"mno", flags)

# sendto errors
# it's successfully used earlier
with pytest.raises(NotImplementedError, match="^FakeNet send flags must be 0, not"):
with pytest.raises(
NotImplementedError, match=r"^FakeNet send flags must be 0, not"
):
await s2.sendto(b"mno", flags, s1.getsockname())
with pytest.raises(TypeError, match="wrong number of arguments$"):
with pytest.raises(TypeError, match=r"wrong number of arguments$"):
await s2.sendto(b"mno", flags, s1.getsockname(), "extra arg") # type: ignore[call-overload]


Expand Down Expand Up @@ -184,7 +188,7 @@ async def test_nonwindows_functionality() -> None:

with pytest.raises(
AttributeError,
match="^'FakeSocket' object has no attribute 'share'$",
match=r"^'FakeSocket' object has no attribute 'share'$",
):
await s1.share(0) # type: ignore[attr-defined]

Expand All @@ -202,17 +206,17 @@ async def test_windows_functionality() -> None:
await s1.bind(("127.0.0.1", 0))
with pytest.raises(
AttributeError,
match="^'FakeSocket' object has no attribute 'sendmsg'$",
match=r"^'FakeSocket' object has no attribute 'sendmsg'$",
):
await s1.sendmsg([b"jkl"], (), 0, s2.getsockname()) # type: ignore[attr-defined]
with pytest.raises(
AttributeError,
match="^'FakeSocket' object has no attribute 'recvmsg'$",
match=r"^'FakeSocket' object has no attribute 'recvmsg'$",
):
s2.recvmsg(0) # type: ignore[attr-defined]
with pytest.raises(
AttributeError,
match="^'FakeSocket' object has no attribute 'recvmsg_into'$",
match=r"^'FakeSocket' object has no attribute 'recvmsg_into'$",
):
s2.recvmsg_into([]) # type: ignore[attr-defined]
with pytest.raises(NotImplementedError):
Expand All @@ -239,7 +243,7 @@ async def test_not_implemented_functions() -> None:
# setsockopt
with pytest.raises(
NotImplementedError,
match="^FakeNet always has IPV6_V6ONLY=True$",
match=r"^FakeNet always has IPV6_V6ONLY=True$",
):
s1.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
with pytest.raises(
Expand All @@ -257,7 +261,7 @@ async def test_not_implemented_functions() -> None:
s1.set_inheritable(False)
with pytest.raises(
NotImplementedError,
match="^FakeNet can't make inheritable sockets$",
match=r"^FakeNet can't make inheritable sockets$",
):
s1.set_inheritable(True)

Expand All @@ -276,7 +280,7 @@ async def test_getpeername() -> None:

with pytest.raises(
AssertionError,
match="^This method seems to assume that self._binding has a remote UDPEndpoint$",
match=r"^This method seems to assume that self._binding has a remote UDPEndpoint$",
):
s1.getpeername()

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_highlevel_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def aclose(self) -> NoReturn:

stapled = StapledStream(BrokenSendStream(), BrokenReceiveStream())

with pytest.raises(ValueError, match="^(send|recv) error$") as excinfo:
with pytest.raises(ValueError, match=r"^(send|recv) error$") as excinfo:
await stapled.aclose()
assert isinstance(excinfo.value.__context__, ValueError)

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_highlevel_open_tcp_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def test_open_tcp_listeners_rebind() -> None:
probe.setsockopt(stdlib_socket.SOL_SOCKET, stdlib_socket.SO_REUSEADDR, 1)
with pytest.raises(
OSError,
match="(Address (already )?in use|An attempt was made to access a socket in a way forbidden by its access permissions)$",
match=r"(Address (already )?in use|An attempt was made to access a socket in a way forbidden by its access permissions)$",
):
probe.bind(sockaddr1)

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_highlevel_open_tcp_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def test_open_tcp_stream_real_socket_smoketest() -> None:


async def test_open_tcp_stream_input_validation() -> None:
with pytest.raises(ValueError, match="^host must be str or bytes, not None$"):
with pytest.raises(ValueError, match=r"^host must be str or bytes, not None$"):
await open_tcp_stream(None, 80) # type: ignore[arg-type]
with pytest.raises(TypeError):
await open_tcp_stream("127.0.0.1", b"80") # type: ignore[arg-type]
Expand Down
Loading

0 comments on commit 174bd07

Please sign in to comment.