diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2013-10-17 13:40:57 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2013-10-17 13:40:57 (GMT) |
commit | 240f86d7ddbeb3800d39a6d2e6e7a7d1f0c49799 (patch) | |
tree | ec61711162ebf82864716dee27119461c312ba58 /Doc/library/contextlib.rst | |
parent | 1eb509a585c402faa76da85095f1bdae5cd54ef2 (diff) | |
download | cpython-240f86d7ddbeb3800d39a6d2e6e7a7d1f0c49799.zip cpython-240f86d7ddbeb3800d39a6d2e6e7a7d1f0c49799.tar.gz cpython-240f86d7ddbeb3800d39a6d2e6e7a7d1f0c49799.tar.bz2 |
Close #19266: contextlib.ignore -> contextlib.suppress
Patch by Zero Piraeus.
Diffstat (limited to 'Doc/library/contextlib.rst')
-rw-r--r-- | Doc/library/contextlib.rst | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 0359750..669c04a 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -95,22 +95,27 @@ Functions and classes provided: ``page.close()`` will be called when the :keyword:`with` block is exited. -.. function:: ignore(*exceptions) +.. function:: suppress(*exceptions) - Return a context manager that ignores the specified exceptions if they - occur in the body of a with-statement. + Return a context manager that suppresses any of the specified exceptions + if they occur in the body of a with statement and then resumes execution + with the first statement following the end of the with statement. - As with any other mechanism that completely suppresses exceptions, it - should only be used to cover very specific errors where silently - ignoring the exception is known to be the right thing to do. + As with any other mechanism that completely suppresses exceptions, this + context manager should be used only to cover very specific errors where + silently continuing with program execution is known to be the right + thing to do. For example:: - from contextlib import ignore + from contextlib import suppress - with ignore(FileNotFoundError): + with suppress(FileNotFoundError): os.remove('somefile.tmp') + with suppress(FileNotFoundError): + os.remove('someotherfile.tmp') + This code is equivalent to:: try: @@ -118,6 +123,11 @@ Functions and classes provided: except FileNotFoundError: pass + try: + os.remove('someotherfile.tmp') + except FileNotFoundError: + pass + .. versionadded:: 3.4 |