FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.10] Formatting fixes in contextlib docs (GH-98111) by miss-islington · Pull Request #98206 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 17 additions & 11 deletions Doc/library/contextlib.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Functions and classes provided:
# Code to release resource, e.g.:
release_resource(resource)

The function can then be used like this::

>>> with managed_resource(timeout=3600) as resource:
... # Resource is released at the end of this block,
... # even if code in the block raises an exception
Expand Down Expand Up @@ -140,9 +142,9 @@ Functions and classes provided:
finally:
print(f'it took {time.monotonic() - now}s to run')

@timeit()
async def main():
# ... async code ...
@timeit()
async def main():
# ... async code ...

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

async def send_http(session=None):
if not session:
# If no http session, create it with aiohttp
cm = aiohttp.ClientSession()
else:
# Caller is responsible for closing the session
cm = nullcontext(session)
if not session:
# If no http session, create it with aiohttp
cm = aiohttp.ClientSession()
else:
# Caller is responsible for closing the session
cm = nullcontext(session)

async with cm as session:
# Send http requests with session
async with cm as session:
# Send http requests with session

.. versionadded:: 3.7

Expand Down Expand Up @@ -379,6 +381,8 @@ Functions and classes provided:
print('Finishing')
return False

The class can then be used like this::

>>> @mycontext()
... def function():
... print('The bit in the middle')
Expand Down Expand Up @@ -449,6 +453,8 @@ Functions and classes provided:
print('Finishing')
return False

The class can then be used like this::

>>> @mycontext()
... async def function():
... print('The bit in the middle')
Expand Down

Back | FazBrowse Home | New Git URL