Skip to content

Commit 3b33c20

Browse files
authored
Formatting fixes in contextlib docs (#98111)
1 parent e3bf125 commit 3b33c20

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

Doc/library/contextlib.rst

+17-11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Functions and classes provided:
6666
# Code to release resource, e.g.:
6767
release_resource(resource)
6868

69+
The function can then be used like this::
70+
6971
>>> with managed_resource(timeout=3600) as resource:
7072
... # Resource is released at the end of this block,
7173
... # even if code in the block raises an exception
@@ -140,9 +142,9 @@ Functions and classes provided:
140142
finally:
141143
print(f'it took {time.monotonic() - now}s to run')
142144

143-
@timeit()
144-
async def main():
145-
# ... async code ...
145+
@timeit()
146+
async def main():
147+
# ... async code ...
146148

147149
When used as a decorator, a new generator instance is implicitly created on
148150
each function call. This allows the otherwise "one-shot" context managers
@@ -249,15 +251,15 @@ Functions and classes provided:
249251
:ref:`asynchronous context managers <async-context-managers>`::
250252

251253
async def send_http(session=None):
252-
if not session:
253-
# If no http session, create it with aiohttp
254-
cm = aiohttp.ClientSession()
255-
else:
256-
# Caller is responsible for closing the session
257-
cm = nullcontext(session)
254+
if not session:
255+
# If no http session, create it with aiohttp
256+
cm = aiohttp.ClientSession()
257+
else:
258+
# Caller is responsible for closing the session
259+
cm = nullcontext(session)
258260

259-
async with cm as session:
260-
# Send http requests with session
261+
async with cm as session:
262+
# Send http requests with session
261263

262264
.. versionadded:: 3.7
263265

@@ -396,6 +398,8 @@ Functions and classes provided:
396398
print('Finishing')
397399
return False
398400

401+
The class can then be used like this::
402+
399403
>>> @mycontext()
400404
... def function():
401405
... print('The bit in the middle')
@@ -466,6 +470,8 @@ Functions and classes provided:
466470
print('Finishing')
467471
return False
468472

473+
The class can then be used like this::
474+
469475
>>> @mycontext()
470476
... async def function():
471477
... print('The bit in the middle')

0 commit comments

Comments
 (0)