Skip to content

Commit 1254b40

Browse files
committed
Rename contextlib.ignored() to contextlib.ignore().
1 parent a76795b commit 1254b40

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

Doc/library/contextlib.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ Functions and classes provided:
9494
without needing to explicitly close ``page``. Even if an error occurs,
9595
``page.close()`` will be called when the :keyword:`with` block is exited.
9696

97-
.. function:: ignored(*exceptions)
97+
.. function:: ignore(*exceptions)
9898

9999
Return a context manager that ignores the specified exceptions if they
100100
occur in the body of a with-statement.
101101

102102
For example::
103103

104-
from contextlib import ignored
104+
from contextlib import ignore
105105

106-
with ignored(OSError):
106+
with ignore(OSError):
107107
os.remove('somefile.tmp')
108108

109109
This code is equivalent to::

Lib/contextlib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from functools import wraps
66

77
__all__ = ["contextmanager", "closing", "ContextDecorator", "ExitStack",
8-
"ignored", "redirect_stdout"]
8+
"ignore", "redirect_stdout"]
99

1010

1111
class ContextDecorator(object):
@@ -179,10 +179,10 @@ def __exit__(self, exctype, excinst, exctb):
179179
sys.stdout = self.old_target
180180

181181
@contextmanager
182-
def ignored(*exceptions):
182+
def ignore(*exceptions):
183183
"""Context manager to ignore specified exceptions
184184
185-
with ignored(OSError):
185+
with ignore(OSError):
186186
os.remove(somefile)
187187
188188
"""

Lib/test/test_contextlib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,26 +632,26 @@ class Example(object): pass
632632
stack.push(cm)
633633
self.assertIs(stack._exit_callbacks[-1], cm)
634634

635-
class TestIgnored(unittest.TestCase):
635+
class TestIgnore(unittest.TestCase):
636636

637637
def test_no_exception(self):
638638

639-
with ignored(ValueError):
639+
with ignore(ValueError):
640640
self.assertEqual(pow(2, 5), 32)
641641

642642
def test_exact_exception(self):
643643

644-
with ignored(TypeError):
644+
with ignore(TypeError):
645645
len(5)
646646

647647
def test_multiple_exception_args(self):
648648

649-
with ignored(ZeroDivisionError, TypeError):
649+
with ignore(ZeroDivisionError, TypeError):
650650
len(5)
651651

652652
def test_exception_hierarchy(self):
653653

654-
with ignored(LookupError):
654+
with ignore(LookupError):
655655
'Hello'[50]
656656

657657
class TestRedirectStdout(unittest.TestCase):

Misc/NEWS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,8 +1656,8 @@ Library
16561656
- Issue #17385: Fix quadratic behavior in threading.Condition. The FIFO
16571657
queue now uses a deque instead of a list.
16581658

1659-
- Issue #15806: Add contextlib.ignored(). This creates a context manager
1660-
to ignore specified exceptions, replacing the "except Exc: pass" idiom.
1659+
- Issue #15806: Add contextlib.ignore(). This creates a context manager to
1660+
ignore specified exceptions, replacing the "except SomeException: pass" idiom.
16611661

16621662
- Issue #14645: The email generator classes now produce output using the
16631663
specified linesep throughout. Previously if the prolog, epilog, or

0 commit comments

Comments
 (0)