Skip to content

Commit f0cb052

Browse files
committed
use code-block instead of code
1 parent 91edf89 commit f0cb052

File tree

8 files changed

+69
-69
lines changed

8 files changed

+69
-69
lines changed

docs/source/contributing.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ you can use ``# pragma: no cover`` to mark lines where
201201
lack-of-coverage isn't something that we'd want to fix (as opposed to
202202
it being merely hard to fix). For example:
203203

204-
.. code:: python
204+
.. code-block:: python
205205
206206
if ...:
207207
...
@@ -295,7 +295,7 @@ format all our code to a standard style. While you're editing code you
295295
can be as sloppy as you like about whitespace; and then before you commit,
296296
just run:
297297

298-
.. code::
298+
.. code-block::
299299
300300
pip install -U pre-commit
301301
pre-commit
@@ -309,14 +309,14 @@ nicely formatted. (black doesn't reformat comments or docstrings.)
309309
If you would like, you can even have pre-commit run before you commit by
310310
running:
311311

312-
.. code::
312+
.. code-block::
313313
314314
pre-commit install
315315
316316
and now pre-commit will run before git commits. You can uninstall the
317317
pre-commit hook at any time by running:
318318

319-
.. code::
319+
.. code-block::
320320
321321
pre-commit uninstall
322322
@@ -326,7 +326,7 @@ you can can add ``# fmt: off`` and ``# fmt: on`` comments.
326326

327327
If you want to see what changes black will make, you can use:
328328

329-
.. code::
329+
.. code-block::
330330
331331
black --diff trio
332332
@@ -410,7 +410,7 @@ file to install all of the required packages (possibly using a
410410
virtualenv). After that, build the docs using ``make html`` in the
411411
docs directory. The whole process might look something like this:
412412

413-
.. code::
413+
.. code-block::
414414
415415
cd path/to/project/checkout/
416416
pip install -r docs-requirements.txt

docs/source/design.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ soon code has to jump through some hoops to make it happen – but its
314314
most dramatic influence can seen in Trio's task-spawning interface,
315315
where it motivates the use of "nurseries":
316316

317-
.. code:: python
317+
.. code-block:: python
318318
319319
async def parent():
320320
async with trio.open_nursery() as nursery:
@@ -380,7 +380,7 @@ Specific style guidelines
380380
* Any function that takes a callable to run should have a signature
381381
like:
382382

383-
.. code:: python
383+
.. code-block:: python
384384
385385
def call_the_thing(fn, *args, kwonly1, kwonly2):
386386
...
@@ -391,7 +391,7 @@ Specific style guidelines
391391
take any arguments of its own, i.e. in this case its signature looks
392392
like:
393393

394-
.. code:: python
394+
.. code-block:: python
395395
396396
def call_the_thing(fn, *args):
397397
...
@@ -418,7 +418,7 @@ Specific style guidelines
418418
* If it's desirable to have both blocking and non-blocking versions of
419419
a function, then they look like:
420420

421-
.. code:: python
421+
.. code-block:: python
422422
423423
async def OPERATION(arg1, arg2):
424424
...

docs/source/history.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ Highlights
12501250
example, given an appropriate ``http_server_on_random_open_port``
12511251
function, you could write:
12521252

1253-
.. code:: python
1253+
.. code-block:: python
12541254
12551255
port = await nursery.start(http_server_on_random_open_port)
12561256
@@ -1494,7 +1494,7 @@ Other changes
14941494
in the Trio tutorial for more details.) So for example, this isn't
14951495
going to work:
14961496

1497-
.. code:: python
1497+
.. code-block:: python
14981498
14991499
async def main():
15001500
# asyncio here

docs/source/reference-core.rst

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ your function also acts as a checkpoint. If you don't, then it
115115
isn't. So there's nothing stopping someone from writing a function
116116
like:
117117

118-
.. code:: python
118+
.. code-block:: python
119119
120120
# technically legal, but bad style:
121121
async def why_is_this_async():
@@ -140,7 +140,7 @@ to help you keep track of checkpoints. Pretty sneaky, eh?)
140140

141141
A slightly trickier case is a function like:
142142

143-
.. code:: python
143+
.. code-block:: python
144144
145145
async def sleep_or_not(should_sleep):
146146
if should_sleep:
@@ -163,7 +163,7 @@ to make things extra predictable. It's up to you how picky you want to
163163
be in your code. To give you a more realistic example of what this
164164
kind of issue looks like in real life, consider this function:
165165

166-
.. code:: python
166+
.. code-block:: python
167167
168168
async def recv_exactly(sock, nbytes):
169169
data = bytearray()
@@ -257,7 +257,7 @@ A simple timeout example
257257

258258
In the simplest case, you can apply a timeout to a block of code:
259259

260-
.. code:: python
260+
.. code-block:: python
261261
262262
with trio.move_on_after(30):
263263
result = await do_http_get("https://...")
@@ -360,7 +360,7 @@ that raised it, at which point it will stop automatically.
360360

361361
Here's an example:
362362

363-
.. code:: python
363+
.. code-block:: python
364364
365365
print("starting...")
366366
with trio.move_on_after(5):
@@ -391,7 +391,7 @@ easier, :func:`move_on_after`\´s ``__enter__`` function returns an
391391
object representing this cancel scope, which we can use to check
392392
whether this scope caught a :exc:`Cancelled` exception:
393393

394-
.. code:: python
394+
.. code-block:: python
395395
396396
with trio.move_on_after(5) as cancel_scope:
397397
await trio.sleep(10)
@@ -411,7 +411,7 @@ resource clean-up. For example, imagine that we have a function that
411411
connects to a remote server and sends some messages, and then cleans
412412
up on the way out:
413413

414-
.. code:: python
414+
.. code-block:: python
415415
416416
with trio.move_on_after(TIMEOUT):
417417
conn = make_connection()
@@ -440,7 +440,7 @@ is no problem (or at least – it's not Trio's problem). To do this,
440440
create a new scope, and set its :attr:`~CancelScope.shield`
441441
attribute to :data:`True`:
442442

443-
.. code:: python
443+
.. code-block:: python
444444
445445
with trio.move_on_after(TIMEOUT):
446446
conn = make_connection()
@@ -565,7 +565,7 @@ Cheat sheet:
565565
* If you want to impose a timeout on a function, but you don't care
566566
whether it timed out or not:
567567

568-
.. code:: python
568+
.. code-block:: python
569569
570570
with trio.move_on_after(TIMEOUT):
571571
await do_whatever()
@@ -574,7 +574,7 @@ Cheat sheet:
574574
* If you want to impose a timeout on a function, and then do some
575575
recovery if it timed out:
576576

577-
.. code:: python
577+
.. code-block:: python
578578
579579
with trio.move_on_after(TIMEOUT) as cancel_scope:
580580
await do_whatever()
@@ -586,7 +586,7 @@ Cheat sheet:
586586
out then just give up and raise an error for your caller to deal
587587
with:
588588

589-
.. code:: python
589+
.. code-block:: python
590590
591591
with trio.fail_after(TIMEOUT):
592592
await do_whatever()
@@ -622,15 +622,15 @@ you feel like it. Trio is a bit different: you can't start a child
622622
task unless you're prepared to be a responsible parent. The way you
623623
demonstrate your responsibility is by creating a nursery:
624624

625-
.. code:: python
625+
.. code-block:: python
626626
627627
async with trio.open_nursery() as nursery:
628628
...
629629
630630
And once you have a reference to a nursery object, you can start
631631
children in that nursery:
632632

633-
.. code:: python
633+
.. code-block:: python
634634
635635
async def child():
636636
...
@@ -676,7 +676,7 @@ finished.
676676

677677
A return statement will not cancel the nursery if it still has tasks running:
678678

679-
.. code:: python
679+
.. code-block:: python
680680
681681
async def main():
682682
async with trio.open_nursery() as nursery:
@@ -694,7 +694,7 @@ In Trio, child tasks inherit the parent nursery's cancel scopes. So in
694694
this example, both the child tasks will be cancelled when the timeout
695695
expires:
696696

697-
.. code:: python
697+
.. code-block:: python
698698
699699
with trio.move_on_after(TIMEOUT):
700700
async with trio.open_nursery() as nursery:
@@ -706,7 +706,7 @@ Note that what matters here is the scopes that were active when
706706
``start_soon`` is called. So for example, the timeout block below does
707707
nothing at all:
708708

709-
.. code:: python
709+
.. code-block:: python
710710
711711
async with trio.open_nursery() as nursery:
712712
with trio.move_on_after(TIMEOUT): # don't do this!
@@ -727,7 +727,7 @@ Normally, in Python, only one thing happens at a time, which means
727727
that only one thing can go wrong at a time. Trio has no such
728728
limitation. Consider code like:
729729

730-
.. code:: python
730+
.. code-block:: python
731731
732732
async def broken1():
733733
d = {}
@@ -751,7 +751,7 @@ encapsulate multiple exceptions being raised at once.
751751
To catch individual exceptions encapsulated in an exception group, the ``except*``
752752
clause was introduced in Python 3.11 (:pep:`654`). Here's how it works:
753753

754-
.. code:: python
754+
.. code-block:: python
755755
756756
try:
757757
async with trio.open_nursery() as nursery:
@@ -772,7 +772,7 @@ But what if you can't use Python 3.11, and therefore ``except*``, just yet?
772772
The same exceptiongroup_ library which backports `ExceptionGroup` also lets
773773
you approximate this behavior with exception handler callbacks:
774774

775-
.. code:: python
775+
.. code-block:: python
776776
777777
from exceptiongroup import catch
778778
@@ -796,7 +796,7 @@ The semantics for the handler functions are equal to ``except*`` blocks, except
796796
setting local variables. If you need to set local variables, you need to declare them
797797
inside the handler function(s) with the ``nonlocal`` keyword:
798798

799-
.. code:: python
799+
.. code-block:: python
800800
801801
def handle_keyerrors(excgroup):
802802
nonlocal myflag
@@ -907,7 +907,7 @@ The solution here is simple once you see it: there's no requirement
907907
that a nursery object stay in the task that created it! We can write
908908
code like this:
909909

910-
.. code:: python
910+
.. code-block:: python
911911
912912
async def new_connection_listener(handler, nursery):
913913
while True:
@@ -923,7 +923,7 @@ Notice that ``server`` opens a nursery and passes it to
923923
able to start new tasks as "siblings" of itself. Of course, in this
924924
case, we could just as well have written:
925925

926-
.. code:: python
926+
.. code-block:: python
927927
928928
async def server(handler):
929929
async with trio.open_nursery() as nursery:
@@ -939,7 +939,7 @@ nursery, **not** from the task that calls ``start_soon``. So in this
939939
example, the timeout does *not* apply to ``child`` (or to anything
940940
else):
941941

942-
.. code:: python
942+
.. code-block:: python
943943
944944
async def do_spawn(nursery):
945945
with trio.move_on_after(TIMEOUT): # don't do this, it has no effect
@@ -969,7 +969,7 @@ For example, here's a function that takes a list of functions, runs
969969
them all concurrently, and returns the result from the one that
970970
finishes first:
971971

972-
.. code:: python
972+
.. code-block:: python
973973
974974
async def race(*async_fns):
975975
if not async_fns:
@@ -1169,7 +1169,7 @@ an unfair lock, this would result in the same task holding the lock
11691169
forever and the other task being starved out. But if you run this,
11701170
you'll see that the two tasks politely take turns:
11711171

1172-
.. code:: python
1172+
.. code-block:: python
11731173
11741174
# fairness-demo.py
11751175
@@ -1366,7 +1366,7 @@ objects using ``async with``. Another option is to pass clones into
13661366
all-but-one of the child tasks, and then pass the original object into
13671367
the last task, like:
13681368

1369-
.. code:: python
1369+
.. code-block:: python
13701370
13711371
# Also works, but is more finicky:
13721372
send_channel, receive_channel = trio.open_memory_channel(0)
@@ -1380,7 +1380,7 @@ the producers/consumers.
13801380

13811381
Just make sure that you don't write:
13821382

1383-
.. code:: python
1383+
.. code-block:: python
13841384
13851385
# Broken, will cause program to hang:
13861386
send_channel, receive_channel = trio.open_memory_channel(0)
@@ -1586,7 +1586,7 @@ over them. :pep:`525` has many more details if you want them.
15861586
For example, the following is a roundabout way to print
15871587
the numbers 0 through 9 with a 1-second delay before each one:
15881588

1589-
.. code:: python
1589+
.. code-block:: python
15901590
15911591
async def range_slowly(*args):
15921592
"""Like range(), but adds a 1-second sleep before each value."""
@@ -1636,7 +1636,7 @@ soon as you're done using it, then you'll need to wrap your use of the
16361636
generator in something like `async_generator.aclosing()
16371637
<https://async-generator.readthedocs.io/en/latest/reference.html#context-managers>`__:
16381638

1639-
.. code:: python
1639+
.. code-block:: python
16401640
16411641
# Instead of this:
16421642
async for value in my_generator():
@@ -1696,7 +1696,7 @@ Cancel scopes and nurseries
16961696

16971697
That is, this is OK:
16981698

1699-
.. code:: python
1699+
.. code-block:: python
17001700
17011701
async def some_agen():
17021702
with trio.move_on_after(1):
@@ -1710,7 +1710,7 @@ That is, this is OK:
17101710
17111711
But this is not:
17121712

1713-
.. code:: python
1713+
.. code-block:: python
17141714
17151715
async def some_agen():
17161716
with trio.move_on_after(1):
@@ -1857,7 +1857,7 @@ example of defining a custom policy that respects the global thread
18571857
limit, while making sure that no individual user can use more than 3
18581858
threads at a time:
18591859

1860-
.. code:: python
1860+
.. code-block:: python
18611861
18621862
class CombinedLimiter:
18631863
def __init__(self, first, second):

0 commit comments

Comments
 (0)