Skip to content

Commit 3a36759

Browse files
authored
Merge branch 'master' into bump_pyright
2 parents cdce9d5 + 78c55aa commit 3a36759

File tree

95 files changed

+1435
-1150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1435
-1150
lines changed

.github/workflows/autodeps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
contents: write
2020
steps:
2121
- name: Checkout
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323
- name: Setup python
24-
uses: actions/setup-python@v4
24+
uses: actions/setup-python@v5
2525
with:
2626
python-version: "3.8"
2727
- name: Bump dependencies

.github/workflows/ci.yml

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,11 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
# pypy 3.9 and 3.10 are failing, see https://github.com/python-trio/trio/issues/2678 and https://github.com/python-trio/trio/issues/2776 respectively
22-
python: ['3.8', '3.9', '3.10'] #, 'pypy-3.9-nightly', 'pypy-3.10-nightly']
21+
python: ['3.8', '3.9', '3.10']
2322
arch: ['x86', 'x64']
2423
lsp: ['']
2524
lsp_extract_file: ['']
2625
extra_name: ['']
27-
exclude:
28-
# pypy does not release 32-bit binaries
29-
- python: 'pypy-3.9-nightly'
30-
arch: 'x86'
31-
#- python: 'pypy-3.10-nightly'
32-
# arch: 'x86'
3326
include:
3427
- python: '3.8'
3528
arch: 'x64'
@@ -57,9 +50,9 @@ jobs:
5750
}}
5851
steps:
5952
- name: Checkout
60-
uses: actions/checkout@v3
53+
uses: actions/checkout@v4
6154
- name: Setup python
62-
uses: actions/setup-python@v4
55+
uses: actions/setup-python@v5
6356
with:
6457
# This allows the matrix to specify just the major.minor version while still
6558
# expanding it to get the latest patch version including alpha releases.
@@ -94,7 +87,7 @@ jobs:
9487
strategy:
9588
fail-fast: false
9689
matrix:
97-
python: ['pypy-3.9', 'pypy-3.10', '3.8', '3.9', '3.10', '3.11', '3.12-dev', 'pypy-3.9-nightly', 'pypy-3.10-nightly']
90+
python: ['pypy-3.9', 'pypy-3.10', '3.8', '3.9', '3.10', '3.11', '3.12']
9891
check_formatting: ['0']
9992
no_test_requirements: ['0']
10093
extra_name: ['']
@@ -117,9 +110,9 @@ jobs:
117110
}}
118111
steps:
119112
- name: Checkout
120-
uses: actions/checkout@v3
113+
uses: actions/checkout@v4
121114
- name: Setup python
122-
uses: actions/setup-python@v4
115+
uses: actions/setup-python@v5
123116
if: "!endsWith(matrix.python, '-dev')"
124117
with:
125118
python-version: ${{ fromJSON(format('["{0}", "{1}"]', format('{0}.0-alpha - {0}.X', matrix.python), matrix.python))[startsWith(matrix.python, 'pypy')] }}
@@ -150,7 +143,7 @@ jobs:
150143
strategy:
151144
fail-fast: false
152145
matrix:
153-
python: ['3.8', '3.9', '3.10', 'pypy-3.9-nightly', 'pypy-3.10-nightly']
146+
python: ['3.8', '3.9', '3.10']
154147
continue-on-error: >-
155148
${{
156149
(
@@ -162,9 +155,9 @@ jobs:
162155
}}
163156
steps:
164157
- name: Checkout
165-
uses: actions/checkout@v3
158+
uses: actions/checkout@v4
166159
- name: Setup python
167-
uses: actions/setup-python@v4
160+
uses: actions/setup-python@v5
168161
with:
169162
python-version: ${{ fromJSON(format('["{0}", "{1}"]', format('{0}.0-alpha - {0}.X', matrix.python), matrix.python))[startsWith(matrix.python, 'pypy')] }}
170163
cache: pip
@@ -179,6 +172,65 @@ jobs:
179172
name: macOS (${{ matrix.python }})
180173
flags: macOS,${{ matrix.python }}
181174

175+
# run CI on a musl linux
176+
Alpine:
177+
name: "Alpine"
178+
runs-on: ubuntu-latest
179+
container: alpine
180+
steps:
181+
- name: Checkout
182+
uses: actions/checkout@v4
183+
- name: Install necessary packages
184+
# can't use setup-python because that python doesn't seem to work;
185+
# `python3-dev` (rather than `python:alpine`) for some ctypes reason,
186+
# `nodejs` for pyright (`node-env` pulls in nodejs but that takes a while and can time out the test).
187+
run: apk update && apk add python3-dev bash nodejs
188+
- name: Enter virtual environment
189+
run: python -m venv .venv
190+
- name: Run tests
191+
run: source .venv/bin/activate && ./ci.sh
192+
- if: always()
193+
uses: codecov/codecov-action@v3
194+
with:
195+
directory: empty
196+
token: 87cefb17-c44b-4f2f-8b30-1fff5769ce46
197+
name: Alpine
198+
flags: Alpine,3.12
199+
200+
Cython:
201+
name: "Cython"
202+
runs-on: ubuntu-latest
203+
strategy:
204+
fail-fast: false
205+
matrix:
206+
python: ['3.8', '3.12']
207+
steps:
208+
- name: Checkout
209+
uses: actions/checkout@v4
210+
- name: Setup python
211+
uses: actions/setup-python@v5
212+
with:
213+
python-version: '${{ matrix.python }}'
214+
cache: pip
215+
# setuptools is needed to get distutils on 3.12, which cythonize requires
216+
- name: install trio and setuptools
217+
run: python -m pip install --upgrade pip . setuptools
218+
219+
- name: install cython<3
220+
run: python -m pip install "cython<3"
221+
- name: compile pyx file
222+
run: cythonize -i tests/cython/test_cython.pyx
223+
- name: import & run module
224+
run: python -c 'import tests.cython.test_cython'
225+
226+
- name: install cython>=3
227+
run: python -m pip install "cython>=3"
228+
- name: compile pyx file
229+
# different cython version should trigger a re-compile, but --force just in case
230+
run: cythonize --inplace --force tests/cython/test_cython.pyx
231+
- name: import & run module
232+
run: python -c 'import tests.cython.test_cython'
233+
182234
# https://github.com/marketplace/actions/alls-green#why
183235
check: # This job does nothing and is only used for the branch protection
184236

@@ -188,6 +240,8 @@ jobs:
188240
- Windows
189241
- Ubuntu
190242
- macOS
243+
- Alpine
244+
- Cython
191245

192246
runs-on: ubuntu-latest
193247

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ repos:
1919
- id: sort-simple-yaml
2020
files: .pre-commit-config.yaml
2121
- repo: https://github.com/psf/black-pre-commit-mirror
22-
rev: 23.12.1
22+
rev: 24.2.0
2323
hooks:
2424
- id: black
2525
- repo: https://github.com/astral-sh/ruff-pre-commit
26-
rev: v0.1.11
26+
rev: v0.2.2
2727
hooks:
2828
- id: ruff
2929
types: [file]

docs-requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ towncrier
99

1010
# Trio's own dependencies
1111
cffi; os_name == "nt"
12-
attrs >= 19.2.0
12+
attrs >= 23.2.0
1313
sortedcontainers
1414
idna
1515
outcome

docs-requirements.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ attrs==23.2.0
1212
# outcome
1313
babel==2.14.0
1414
# via sphinx
15-
certifi==2023.11.17
15+
certifi==2024.2.2
1616
# via requests
1717
cffi==1.16.0
1818
# via cryptography
1919
charset-normalizer==3.3.2
2020
# via requests
2121
click==8.1.7
2222
# via towncrier
23-
cryptography==41.0.7
23+
cryptography==42.0.2
2424
# via pyopenssl
2525
docutils==0.20.1
2626
# via
@@ -42,12 +42,12 @@ importlib-resources==6.1.1
4242
# via towncrier
4343
incremental==22.10.0
4444
# via towncrier
45-
jinja2==3.1.2
45+
jinja2==3.1.3
4646
# via
4747
# -r docs-requirements.in
4848
# sphinx
4949
# towncrier
50-
markupsafe==2.1.3
50+
markupsafe==2.1.5
5151
# via jinja2
5252
outcome==1.3.0.post0
5353
# via -r docs-requirements.in
@@ -57,9 +57,9 @@ pycparser==2.21
5757
# via cffi
5858
pygments==2.17.2
5959
# via sphinx
60-
pyopenssl==23.3.0
60+
pyopenssl==24.0.0
6161
# via -r docs-requirements.in
62-
pytz==2023.3.post1
62+
pytz==2024.1
6363
# via babel
6464
requests==2.31.0
6565
# via sphinx
@@ -99,7 +99,7 @@ tomli==2.0.1
9999
# via towncrier
100100
towncrier==23.11.0
101101
# via -r docs-requirements.in
102-
urllib3==2.1.0
102+
urllib3==2.2.0
103103
# via requests
104104
zipp==3.17.0
105105
# via

docs/source/awesome-trio-libraries.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Testing
9494
* `hypothesis-trio <https://github.com/python-trio/hypothesis-trio>`__ - Hypothesis plugin for trio.
9595
* `trustme <https://github.com/python-trio/trustme>`__ - #1 quality TLS certs while you wait, for the discerning tester.
9696
* `pytest-aio <https://github.com/klen/pytest-aio>`_ - Pytest plugin with support for trio, curio, asyncio
97+
* `logot <https://github.com/etianen/logot>`_ - Test whether your async code is logging correctly.
9798

9899

99100
Tools and Utilities
@@ -106,6 +107,7 @@ Tools and Utilities
106107
* `perf-timer <https://github.com/belm0/perf-timer>`__ - A code timer with Trio async support (see ``TrioPerfTimer``). Collects execution time of a block of code excluding time when the coroutine isn't scheduled, such as during blocking I/O and sleep. Also offers ``trio_perf_counter()`` for low-level timing.
107108
* `aiometer <https://github.com/florimondmanca/aiometer>`__ - Execute lots of tasks concurrently while controlling concurrency limits
108109
* `triotp <https://linkdd.github.io/triotp>`__ - OTP framework for Python Trio
110+
* `aioresult <https://github.com/arthur-tacca/aioresult>`__ - Get the return value of a background async function in Trio or anyio, along with a simple Future class and wait utilities
109111

110112
Trio/Asyncio Interoperability
111113
-----------------------------

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def add_mapping(
223223

224224
# General information about the project.
225225
project = "Trio"
226-
copyright = "2017, Nathaniel J. Smith"
226+
copyright = "2017, Nathaniel J. Smith" # noqa: A001 # Name shadows builtin
227227
author = "Nathaniel J. Smith"
228228

229229
# The version info for the project you're documenting, acts as replacement for

docs/source/history.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ Release history
55

66
.. towncrier release notes start
77
8+
Trio 0.24.0 (2024-01-10)
9+
------------------------
10+
11+
Features
12+
~~~~~~~~
13+
14+
- New helper classes: :class:`~.testing.RaisesGroup` and :class:`~.testing.Matcher`.
15+
16+
In preparation for changing the default of ``strict_exception_groups`` to `True`, we're introducing a set of helper classes that can be used in place of `pytest.raises <https://docs.pytest.org/en/stable/reference/reference.html#pytest.raises>`_ in tests, to check for an expected `ExceptionGroup`.
17+
These are provisional, and only planned to be supplied until there's a good solution in ``pytest``. See https://github.com/pytest-dev/pytest/issues/11538 (`#2785 <https://github.com/python-trio/trio/issues/2785>`__)
18+
19+
20+
Deprecations and removals
21+
~~~~~~~~~~~~~~~~~~~~~~~~~
22+
23+
- ``MultiError`` has been fully removed, and all relevant trio functions now raise ExceptionGroups instead. This should not affect end users that have transitioned to using ``except*`` or catching ExceptionGroup/BaseExceptionGroup. (`#2891 <https://github.com/python-trio/trio/issues/2891>`__)
24+
25+
826
Trio 0.23.2 (2023-12-14)
927
------------------------
1028

docs/source/reference-core.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,14 @@ inside the handler function(s) with the ``nonlocal`` keyword::
768768
async with trio.open_nursery() as nursery:
769769
nursery.start_soon(broken1)
770770

771+
.. _strict_exception_groups:
772+
771773
"Strict" versus "loose" ExceptionGroup semantics
772774
++++++++++++++++++++++++++++++++++++++++++++++++
773775

776+
..
777+
TODO: rewrite this (and possible other) sections from the new strict-by-default perspective, under the heading "Deprecated: non-strict ExceptionGroups" - to explain that it only exists for backwards-compatibility, will be removed in future, and that we recommend against it for all new code.
778+
774779
Ideally, in some abstract sense we'd want everything that *can* raise an
775780
`ExceptionGroup` to *always* raise an `ExceptionGroup` (rather than, say, a single
776781
`ValueError`). Otherwise, it would be easy to accidentally write something like ``except
@@ -796,9 +801,10 @@ to set the default behavior for any nursery in your program that doesn't overrid
796801
wrapping, so you'll get maximum compatibility with code that was written to
797802
support older versions of Trio.
798803

799-
To maintain backwards compatibility, the default is ``strict_exception_groups=False``.
800-
The default will eventually change to ``True`` in a future version of Trio, once
801-
Python 3.11 and later versions are in wide use.
804+
The default is set to ``strict_exception_groups=True``, in line with the default behaviour
805+
of ``TaskGroup`` in asyncio and anyio. We've also found that non-strict mode makes it
806+
too easy to neglect the possibility of several exceptions being raised concurrently,
807+
causing nasty latent bugs when errors occur under load.
802808

803809
.. _exceptiongroup: https://pypi.org/project/exceptiongroup/
804810

docs/source/reference-testing.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Inter-task ordering
7272

7373
.. autofunction:: wait_all_tasks_blocked
7474

75+
.. autofunction:: wait_all_threads_completed
76+
77+
.. autofunction:: active_thread_count
78+
7579

7680
.. _testing-streams:
7781

docs/source/typevars.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
See https://github.com/sphinx-doc/sphinx/issues/7722 also.
44
"""
5+
56
from __future__ import annotations
67

78
import re

newsfragments/2785.feature.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.

newsfragments/2786.breaking.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The :ref:`strict_exception_groups <strict_exception_groups>` parameter now defaults to `True` in `trio.run` and `trio.lowlevel.start_guest_run`. `trio.open_nursery` still defaults to the same value as was specified in `trio.run`/`trio.lowlevel.start_guest_run`, but if you didn't specify it there then all subsequent calls to `trio.open_nursery` will change.
2+
This is unfortunately very tricky to change with a deprecation period, as raising a `DeprecationWarning` whenever :ref:`strict_exception_groups <strict_exception_groups>` is not specified would raise a lot of unnecessary warnings.
3+
4+
Notable side effects of changing code to run with ``strict_exception_groups==True``
5+
6+
* If an iterator raises `StopAsyncIteration` or `StopIteration` inside a nursery, then python will not recognize wrapped instances of those for stopping iteration.
7+
* `trio.run_process` is now documented that it can raise an `ExceptionGroup`. It previously could do this in very rare circumstances, but with :ref:`strict_exception_groups <strict_exception_groups>` set to `True` it will now do so whenever exceptions occur in ``deliver_cancel`` or with problems communicating with the subprocess.
8+
9+
* Errors in opening the process is now done outside the internal nursery, so if code previously ran with ``strict_exception_groups=True`` there are cases now where an `ExceptionGroup` is *no longer* added.
10+
* `trio.TrioInternalError` ``.__cause__`` might be wrapped in one or more `ExceptionGroups <ExceptionGroup>`

newsfragments/2891.deprecated.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

newsfragments/2937.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `trio.testing.wait_all_threads_completed`, which blocks until no threads are running tasks. This is intended to be used in the same way as `trio.testing.wait_all_tasks_blocked`.

newsfragments/2939.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The pthread functions are now correctly found on systems using vanilla versions of musl libc.

notes-to-self/time-wait.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
import errno
3030
import socket
3131

32-
import attr
32+
import attrs
3333

3434

35-
@attr.s(repr=False)
35+
@attrs.define(repr=False, slots=False)
3636
class Options:
37-
listen1_early = attr.ib(default=None)
38-
listen1_middle = attr.ib(default=None)
39-
listen1_late = attr.ib(default=None)
40-
server = attr.ib(default=None)
41-
listen2 = attr.ib(default=None)
37+
listen1_early = None
38+
listen1_middle = None
39+
listen1_late = None
40+
server = None
41+
listen2 = None
4242

4343
def set(self, which, sock):
4444
value = getattr(self, which)
@@ -47,7 +47,7 @@ def set(self, which, sock):
4747

4848
def describe(self):
4949
info = []
50-
for f in attr.fields(self.__class__):
50+
for f in attrs.fields(self.__class__):
5151
value = getattr(self, f.name)
5252
if value is not None:
5353
info.append(f"{f.name}={value}")

0 commit comments

Comments
 (0)