diff options
author | Raymond Hettinger <python@rcn.com> | 2013-03-11 05:26:51 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-03-11 05:26:51 (GMT) |
commit | e318a883fece5d9a45165670b5f995886f524820 (patch) | |
tree | bc9a655a3d7c0636940f6decf9b1f73f5bb97856 /Doc/library/contextlib.rst | |
parent | c0417357d14b72763ba919728a1449373d122647 (diff) | |
download | cpython-e318a883fece5d9a45165670b5f995886f524820.zip cpython-e318a883fece5d9a45165670b5f995886f524820.tar.gz cpython-e318a883fece5d9a45165670b5f995886f524820.tar.bz2 |
Issue #15806: Add contextlib.ignored().
Diffstat (limited to 'Doc/library/contextlib.rst')
-rw-r--r-- | Doc/library/contextlib.rst | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 41dfded..4c8fe78 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -94,6 +94,26 @@ Functions and classes provided: without needing to explicitly close ``page``. Even if an error occurs, ``page.close()`` will be called when the :keyword:`with` block is exited. +.. function:: ignored(*exceptions) + + Return a context manager that ignores the specified expections if they + occur in the body of a with-statement. + + For example:: + + from contextlib import ignored + + with ignored(OSError): + os.remove('somefile.tmp') + + This code is equivalent to:: + + try: + os.remove('somefile.tmp') + except OSError: + pass + + .. versionadded:: 3.4 .. class:: ContextDecorator() |