diff options
author | Raymond Hettinger <python@rcn.com> | 2013-10-11 05:39:39 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-10-11 05:39:39 (GMT) |
commit | 1254b407ac6960ff2594e417d2f1c2c6a1ffc755 (patch) | |
tree | ec8d08e5216d84deb67d123a095a716fa1c29407 | |
parent | a76795bf532169674f4e1637585ff6a52359e1c8 (diff) | |
download | cpython-1254b407ac6960ff2594e417d2f1c2c6a1ffc755.zip cpython-1254b407ac6960ff2594e417d2f1c2c6a1ffc755.tar.gz cpython-1254b407ac6960ff2594e417d2f1c2c6a1ffc755.tar.bz2 |
Rename contextlib.ignored() to contextlib.ignore().
-rw-r--r-- | Doc/library/contextlib.rst | 6 | ||||
-rw-r--r-- | Lib/contextlib.py | 6 | ||||
-rw-r--r-- | Lib/test/test_contextlib.py | 10 | ||||
-rw-r--r-- | Misc/NEWS | 4 |
4 files changed, 13 insertions, 13 deletions
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index 4b86755..cac113e 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -94,16 +94,16 @@ 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) +.. function:: ignore(*exceptions) Return a context manager that ignores the specified exceptions if they occur in the body of a with-statement. For example:: - from contextlib import ignored + from contextlib import ignore - with ignored(OSError): + with ignore(OSError): os.remove('somefile.tmp') This code is equivalent to:: diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 868fa6c..41ff9cc 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -5,7 +5,7 @@ from collections import deque from functools import wraps __all__ = ["contextmanager", "closing", "ContextDecorator", "ExitStack", - "ignored", "redirect_stdout"] + "ignore", "redirect_stdout"] class ContextDecorator(object): @@ -179,10 +179,10 @@ class redirect_stdout: sys.stdout = self.old_target @contextmanager -def ignored(*exceptions): +def ignore(*exceptions): """Context manager to ignore specified exceptions - with ignored(OSError): + with ignore(OSError): os.remove(somefile) """ diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index d8a0530..48f8fa9 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -632,26 +632,26 @@ class TestExitStack(unittest.TestCase): stack.push(cm) self.assertIs(stack._exit_callbacks[-1], cm) -class TestIgnored(unittest.TestCase): +class TestIgnore(unittest.TestCase): def test_no_exception(self): - with ignored(ValueError): + with ignore(ValueError): self.assertEqual(pow(2, 5), 32) def test_exact_exception(self): - with ignored(TypeError): + with ignore(TypeError): len(5) def test_multiple_exception_args(self): - with ignored(ZeroDivisionError, TypeError): + with ignore(ZeroDivisionError, TypeError): len(5) def test_exception_hierarchy(self): - with ignored(LookupError): + with ignore(LookupError): 'Hello'[50] class TestRedirectStdout(unittest.TestCase): @@ -1656,8 +1656,8 @@ Library - Issue #17385: Fix quadratic behavior in threading.Condition. The FIFO queue now uses a deque instead of a list. -- Issue #15806: Add contextlib.ignored(). This creates a context manager - to ignore specified exceptions, replacing the "except Exc: pass" idiom. +- Issue #15806: Add contextlib.ignore(). This creates a context manager to + ignore specified exceptions, replacing the "except SomeException: pass" idiom. - Issue #14645: The email generator classes now produce output using the specified linesep throughout. Previously if the prolog, epilog, or |