Skip to content

Commit 5d2b925

Browse files
committed
glossary improvements, rename some rules, add some intersphinx links
1 parent c5298ff commit 5d2b925

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

docs/glossary.rst

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,51 @@ A collection of child Tasks that can run concurrently. Internally contains a :re
7474
* :class:`asyncio.TaskGroup` (since python 3.11)
7575

7676

77+
.. _cancellation:
7778
.. _cancelled:
7879

7980
Cancelled / CancelledError
8081
--------------------------
8182

8283
Handling cancellation is very sensitive, and you generally never want to catch a cancellation exception without letting it propagate to the library.
8384

84-
* Trio: :class:`trio.Cancelled`. `Documentation <https://trio.readthedocs.io/en/stable/reference-core.html#cancellation-and-timeouts>`__
85-
* AnyIO: :func:`anyio.get_cancelled_exc_class`. `Documentation <https://anyio.readthedocs.io/en/stable/cancellation.html>`__
86-
* asyncio: :class:`asyncio.CancelledError`. `Documentation <https://docs.python.org/3/library/asyncio-task.html#task-cancellation>`__
85+
General documentation on cancellation in the different async libraries:
86+
87+
* `Trio <https://trio.readthedocs.io/en/stable/reference-core.html#cancellation-and-timeouts>`__
88+
* `AnyIO <https://anyio.readthedocs.io/en/stable/cancellation.html>`__
89+
* `asyncio <https://docs.python.org/3/library/asyncio-task.html#task-cancellation>`__
90+
91+
Exception classes:
92+
93+
* :class:`trio.Cancelled`
94+
* :func:`anyio.get_cancelled_exc_class`
95+
* :class:`asyncio.CancelledError`
8796

8897
.. _checkpoint:
8998

9099
Checkpoint
91100
----------
92-
Checkpoints are ``await``, ``async for``, and ``async with`` (on at least one of enter/exit). TODO write more and link stuff
101+
Checkpoints are points where the async backend checks for cancellation and invokes scheduling checks. Possible checkpoints are ``await``, ``async for`` (before each iteration, and when exhausting the iterator), and ``async with`` (on at least one of enter/exit).
102+
103+
Trio has extensive and detailed documentation on the concept of :external+trio:ref:`checkpoints <checkpoints>`, and guarantees that all trio async functions will checkpoint (unless they raised an exception).
104+
105+
anyio does not currently have any documentation on checkpoints.
106+
107+
asyncio will checkpoint... ???
108+
109+
To make it easier to reason about checkpoints the :ref:`ASYNC91x <ASYNC910>` rules enforces the same rules as trio for your own project - i.e. all async functions must guarantee a checkpoint (or exception). To make it possible to reason the rules will also assume that all other async functions also adhere to those rules. This means you must be careful if you're using 3rd-party async libraries.
110+
93111

94112
.. _channel_stream_queue:
95113

96114
Channel / Stream / Queue
97115
------------------------
98-
* Trio: `channel <https://trio.readthedocs.io/en/stable/reference-core.html#channels>`__
99-
* AnyIO: `stream <https://anyio.readthedocs.io/en/stable/streams.html#streams>`__
100-
* asyncio: `queue <https://docs.python.org/3/library/asyncio-queue.html>`__
116+
Interfaces used for communicating between tasks, processes, the network, etc.
117+
118+
.. anyio streams is a :doc: and not a :label:, so we can't link with intersphinx :(
119+
120+
.. _anyio_streams: https://anyio.readthedocs.io/en/stable/streams.html#streams
121+
122+
* Trio has :ref:`channels <channels>` for python objects and :ref:`streams <abstract-stream-api>` for bytes.
123+
* AnyIO has ``byte`` and ``object`` `streams <anyio_streams>`_
124+
* asyncio has :ref:`queues <asyncio-queues>` for python objects and :ref:`streams <asyncio-streams>` for bytes.

docs/rules.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
****************
2-
List of rules
3-
****************
1+
*****
2+
Rules
3+
*****
44

55

66
General rules
@@ -40,7 +40,7 @@ ASYNC109 : async-function-with-timeout
4040
Async function definition with a ``timeout`` parameter.
4141
In structured concurrency the caller should instead use :ref:`timeout context managers <timeout_context>`.
4242

43-
ASYNC110 : busy-wait
43+
ASYNC110 : async-busy-wait
4444
``while ...: await [trio/anyio].sleep()`` should be replaced by a :class:`trio.Event`/:class:`anyio.Event`.
4545

4646
ASYNC111 : variable-from-cm-in-start-soon
@@ -57,7 +57,7 @@ ASYNC113 : start-soon-in-aenter
5757
ASYNC114 : startable-not-in-config
5858
Startable function (i.e. has a ``task_status`` keyword parameter) not in :ref:`--startable-in-context-manager <--startable-in-context-manager>` parameter list, please add it so ASYNC113 can catch errors when using it.
5959

60-
ASYNC115 : sleep-zero
60+
ASYNC115 : async-zero-sleep
6161
Replace :func:`trio.sleep(0) <trio.sleep>`/:func:`anyio.sleep(0) <anyio.sleep>` with the more suggestive :func:`trio.lowlevel.checkpoint`/:func:`anyio.lowlevel.checkpoint`.
6262

6363
ASYNC116 : long-sleep-not-forever
@@ -78,44 +78,44 @@ Blocking sync calls in async functions
7878
.. _httpx.Client: https://www.python-httpx.org/api/#client
7979
.. _httpx.AsyncClient: https://www.python-httpx.org/api/#asyncclient
8080
.. _urllib3: https://github.com/urllib3/urllib3
81-
82-
Note: 22X, 23X and 24X has not had asyncio-specific suggestions written.
81+
.. _aiofiles: https://pypi.org/project/aiofiles/
82+
.. _anyio: https://github.com/agronholm/anyio
8383

8484
ASYNC200 : blocking-configured-call
8585
User-configured error for blocking sync calls in async functions.
8686
Does nothing by default, see :ref:`async200-blocking-calls` for how to configure it.
8787

8888
ASYNC210 : blocking-http-call
8989
Sync HTTP call in async function, use `httpx.AsyncClient`_.
90-
This and the other ASYNC21x checks look for usage of `urllib3`_ and `httpx.Client`_, and recommend using `httpx.AsyncClient`_ as that's the largest http client supporting anyio/trio.
90+
This and the other :ref:`ASYNC21x <ASYNC211>` checks look for usage of `urllib3`_ and `httpx.Client`_, and recommend using `httpx.AsyncClient`_ as that's the largest http client supporting anyio/trio.
9191

92-
ASYNC211 : blocking-http-call-pool
92+
_`ASYNC211` : blocking-http-call-pool
9393
Likely sync HTTP call in async function, use `httpx.AsyncClient`_.
9494
Looks for `urllib3`_ method calls on pool objects, but only matching on the method signature and not the object.
9595

9696
ASYNC212 : blocking-http-call-httpx
9797
Blocking sync HTTP call on httpx object, use `httpx.AsyncClient`_.
9898

9999
ASYNC220 : blocking-create-subprocess
100-
Sync call to :class:`subprocess.Popen` (or equivalent) in async function, use :func:`trio.run_process`/:func:`anyio.run_process` in a :ref:`taskgroup_nursery`. ``asyncio`` users can use `asyncio.create_subprocess_[exec/shell] <https://docs.python.org/3/library/asyncio-subprocess.html>`_.
100+
Sync call to :class:`subprocess.Popen` (or equivalent) in async function, use :func:`trio.run_process`/:func:`anyio.run_process`/:ref:`asyncio.create_subprocess_[exec/shell] <asyncio-subprocess>` in a :ref:`taskgroup_nursery`.
101101

102102
ASYNC221 : blocking-run-process
103-
Sync call to :func:`subprocess.run` (or equivalent) in async function, use :func:`trio.run_process`/:func:`anyio.run_process`. ``asyncio`` users can use `asyncio.create_subprocess_[exec/shell] <https://docs.python.org/3/library/asyncio-subprocess.html>`_.
103+
Sync call to :func:`subprocess.run` (or equivalent) in async function, use :func:`trio.run_process`/:func:`anyio.run_process`/:ref:`asyncio.create_subprocess_[exec/shell] <asyncio-subprocess>`.
104104

105105
ASYNC222 : blocking-process-wait
106-
Sync call to :func:`os.wait` (or equivalent) in async function, wrap in :func:`trio.to_thread.run_sync`/:func:`anyio.to_thread.run_sync`. ``asyncio`` users can use `asyncio.loop.run_in_executor <https://docs.python.org/3/library/asyncio-subprocess.html>`_.
106+
Sync call to :func:`os.wait` (or equivalent) in async function, wrap in :func:`trio.to_thread.run_sync`/:func:`anyio.to_thread.run_sync`/:meth:`asyncio.loop.run_in_executor`.
107107

108108
ASYNC230 : blocking-open-call
109-
Sync call to :func:`open` in async function, use :func:`trio.open_file`/:func:`anyio.open_file`. ``asyncio`` users need to use a library such as `aiofiles <https://pypi.org/project/aiofiles/>`_, or switch to `anyio <https://github.com/agronholm/anyio>`_.
109+
Sync call to :func:`open` in async function, use :func:`trio.open_file`/:func:`anyio.open_file`. ``asyncio`` users need to use a library such as `aiofiles`_, or switch to `anyio`_.
110110

111111
ASYNC231 : blocking-fdopen-call
112-
Sync call to :func:`os.fdopen` in async function, use :func:`trio.wrap_file`/:func:`anyio.wrap_file`. ``asyncio`` users need to use a library such as `aiofiles <https://pypi.org/project/aiofiles/>`_, or switch to `anyio <https://github.com/agronholm/anyio>`_.
112+
Sync call to :func:`os.fdopen` in async function, use :func:`trio.wrap_file`/:func:`anyio.wrap_file`. ``asyncio`` users need to use a library such as `aiofiles`_, or switch to `anyio`_.
113113

114114
ASYNC232 : blocking-file-call
115115
Blocking sync call on file object, wrap the file object in :func:`trio.wrap_file`/:func:`anyio.wrap_file` to get an async file object.
116116

117117
ASYNC240 : blocking-path-usage
118-
Avoid using :mod:`os.path` in async functions, prefer using :class:`trio.Path`/:class:`anyio.Path` objects. ``asyncio`` users should consider `aiopath <https://pypi.org/project/aiopath>`__ or `anyio <https://github.com/agronholm/anyio>`__.
118+
Avoid using :mod:`os.path` in async functions, prefer using :class:`trio.Path`/:class:`anyio.Path` objects. ``asyncio`` users should consider `aiopath <https://pypi.org/project/aiopath>`__ or `anyio`_.
119119

120120
ASYNC250 : blocking-input
121121
Builtin :func:`input` should not be called from async function.

0 commit comments

Comments
 (0)