Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf6abb33

Browse files
Formatting fixes in contextlib docs (GH-98111)
(cherry picked from commit3b33c20)Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
1 parentf94e6b4 commitf6abb33

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

‎Doc/library/contextlib.rst‎

Lines changed: 17 additions & 11 deletions
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

@@ -379,6 +381,8 @@ Functions and classes provided:
379381
print('Finishing')
380382
return False
381383

384+
The class can then be used like this::
385+
382386
>>> @mycontext()
383387
... def function():
384388
... print('The bit in the middle')
@@ -449,6 +453,8 @@ Functions and classes provided:
449453
print('Finishing')
450454
return False
451455

456+
The class can then be used like this::
457+
452458
>>> @mycontext()
453459
... async def function():
454460
... print('The bit in the middle')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp