mirror of
https://github.com/python/cpython.git
synced 2025-08-22 01:35:16 +00:00
Formatting fixes in contextlib docs (GH-98111)
(cherry picked from commit 3b33c2010a
)
Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
This commit is contained in:
parent
9e666bc640
commit
59ddbc4ab6
1 changed files with 17 additions and 11 deletions
|
@ -66,6 +66,8 @@ Functions and classes provided:
|
||||||
# Code to release resource, e.g.:
|
# Code to release resource, e.g.:
|
||||||
release_resource(resource)
|
release_resource(resource)
|
||||||
|
|
||||||
|
The function can then be used like this::
|
||||||
|
|
||||||
>>> with managed_resource(timeout=3600) as resource:
|
>>> with managed_resource(timeout=3600) as resource:
|
||||||
... # Resource is released at the end of this block,
|
... # Resource is released at the end of this block,
|
||||||
... # even if code in the block raises an exception
|
... # even if code in the block raises an exception
|
||||||
|
@ -396,6 +398,8 @@ Functions and classes provided:
|
||||||
print('Finishing')
|
print('Finishing')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
The class can then be used like this::
|
||||||
|
|
||||||
>>> @mycontext()
|
>>> @mycontext()
|
||||||
... def function():
|
... def function():
|
||||||
... print('The bit in the middle')
|
... print('The bit in the middle')
|
||||||
|
@ -466,6 +470,8 @@ Functions and classes provided:
|
||||||
print('Finishing')
|
print('Finishing')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
The class can then be used like this::
|
||||||
|
|
||||||
>>> @mycontext()
|
>>> @mycontext()
|
||||||
... async def function():
|
... async def function():
|
||||||
... print('The bit in the middle')
|
... print('The bit in the middle')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue