]> granicus.if.org Git - python/commitdiff
Rename contextlib.ignored() to contextlib.ignore().
authorRaymond Hettinger <python@rcn.com>
Fri, 11 Oct 2013 05:39:39 +0000 (22:39 -0700)
committerRaymond Hettinger <python@rcn.com>
Fri, 11 Oct 2013 05:39:39 +0000 (22:39 -0700)
Doc/library/contextlib.rst
Lib/contextlib.py
Lib/test/test_contextlib.py
Misc/NEWS

index 4b86755bad74c8e075b47414b768952f5f7555e0..cac113e839aadc2b99079a5f37753ebc539c84b2 100644 (file)
@@ -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::
index 868fa6c43d77088d0f6e9fa327330f5fb8828324..41ff9cc448cc304d26dabe60526607e2a1eee470 100644 (file)
@@ -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)
 
     """
index d8a0530689eb787ee5d5991fe423b92042073d39..48f8fa96379c542b07974bcc75af7fc4e72e32f8 100644 (file)
@@ -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):
index 279a5eb3c2e8dc31eee1854c74e17636ba536cd9..9fe1fa6566a1132212d597641732e3f1971c7082 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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