cpython: 22247b7d17fa (original) (raw)

Mercurial > cpython

changeset 86403:22247b7d17fa

Close #19266: contextlib.ignore -> contextlib.suppress Patch by Zero Piraeus. [#19266]

Nick Coghlan ncoghlan@gmail.com
date Thu, 17 Oct 2013 23:40:57 +1000
parents 5cc9cbfb5cff
children 9853d3a20849
files Doc/library/contextlib.rst Doc/whatsnew/3.4.rst Lib/contextlib.py Lib/test/test_contextlib.py Misc/ACKS Misc/NEWS
diffstat 6 files changed, 58 insertions(+), 39 deletions(-)[+] [-] Doc/library/contextlib.rst 26 Doc/whatsnew/3.4.rst 13 Lib/contextlib.py 8 Lib/test/test_contextlib.py 44 Misc/ACKS 1 Misc/NEWS 5

line wrap: on

line diff

--- 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)

+ This code is equivalent to:: try: @@ -118,6 +123,11 @@ Functions and classes provided: except FileNotFoundError: pass

+ .. versionadded:: 3.4

--- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -221,14 +221,17 @@ results should be less than 1% and may b contextlib ---------- -The new :class:contextlib.ignore context manager helps to clarify the -intent of code that deliberately ignores failures from a particular -operation. +The new :class:contextlib.suppress context manager helps to clarify the +intent of code that deliberately suppresses exceptions from a single +statement. (Contributed by Raymond Hettinger in :issue:15806 and +Zero Piraeus in :issue:19266) + The new :class:contextlib.redirect_stdio context manager makes it easier for utility scripts to handle inflexible APIs that don't provide any options to retrieve their output as a string or direct it to somewhere -other than :data:sys.stdout. +other than :data:sys.stdout. (Contribute by Raymond Hettinger in +:issue:15805) dis @@ -283,7 +286,7 @@ result: a bytes object containing the f A pair of new subclasses of :class:~email.message.Message have been added, along with a new sub-module, :mod:~email.contentmanager. All documentation is currently in the new module, which is being added as part of the new -:term:provisional <provosional package> email API. These classes provide a +:term:provisional <provisional package> email API. These classes provide a number of new methods that make extracting content from and inserting content into email messages much easier. See the :mod:~email.contentmanager documentation for details.

--- 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",

class ContextDecorator(object): @@ -179,10 +179,10 @@ class redirect_stdout: sys.stdout = self.old_target @contextmanager -def ignore(*exceptions):

+def suppress(*exceptions):

"""

--- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -632,28 +632,6 @@ class TestExitStack(unittest.TestCase): stack.push(cm) self.assertIs(stack._exit_callbacks[-1], cm) -class TestIgnore(unittest.TestCase): -

-

-

-

-

-

-

-

- class TestRedirectStdout(unittest.TestCase): def test_redirect_to_string_io(self): @@ -663,5 +641,27 @@ class TestRedirectStdout(unittest.TestCa s = f.getvalue() self.assertIn('pow', s) +class TestSuppress(unittest.TestCase): +

+

+

+

+

+

+

+

+ if name == "main": unittest.main()

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -1003,6 +1003,7 @@ Anand B. Pillai François Pinard Tom Pinckney Zach Pincus +Zero Piraeus Michael Piotrowski Antoine Pitrou Jean-François Piéronne

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -42,6 +42,11 @@ Core and Builtins Library ------- +- Issue #19266: Rename the new-in-3.4 contextlib.ignore context manager