Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1254b407
Commit
1254b407
authored
Oct 10, 2013
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename contextlib.ignored() to contextlib.ignore().
parent
a76795bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
13 deletions
+13
-13
Doc/library/contextlib.rst
Doc/library/contextlib.rst
+3
-3
Lib/contextlib.py
Lib/contextlib.py
+3
-3
Lib/test/test_contextlib.py
Lib/test/test_contextlib.py
+5
-5
Misc/NEWS
Misc/NEWS
+2
-2
No files found.
Doc/library/contextlib.rst
View file @
1254b407
...
...
@@ -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:: ignore
d
(*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 ignore
d
from contextlib import ignore
with ignore
d
(OSError):
with ignore(OSError):
os.remove('somefile.tmp')
This code is equivalent to::
...
...
Lib/contextlib.py
View file @
1254b407
...
...
@@ -5,7 +5,7 @@ from collections import deque
from
functools
import
wraps
__all__
=
[
"contextmanager"
,
"closing"
,
"ContextDecorator"
,
"ExitStack"
,
"ignore
d
"
,
"redirect_stdout"
]
"ignore"
,
"redirect_stdout"
]
class
ContextDecorator
(
object
):
...
...
@@ -179,10 +179,10 @@ class redirect_stdout:
sys
.
stdout
=
self
.
old_target
@
contextmanager
def
ignore
d
(
*
exceptions
):
def
ignore
(
*
exceptions
):
"""Context manager to ignore specified exceptions
with ignore
d
(OSError):
with ignore(OSError):
os.remove(somefile)
"""
...
...
Lib/test/test_contextlib.py
View file @
1254b407
...
...
@@ -632,26 +632,26 @@ class TestExitStack(unittest.TestCase):
stack
.
push
(
cm
)
self
.
assertIs
(
stack
.
_exit_callbacks
[
-
1
],
cm
)
class
TestIgnore
d
(
unittest
.
TestCase
):
class
TestIgnore
(
unittest
.
TestCase
):
def
test_no_exception
(
self
):
with
ignore
d
(
ValueError
):
with
ignore
(
ValueError
):
self
.
assertEqual
(
pow
(
2
,
5
),
32
)
def
test_exact_exception
(
self
):
with
ignore
d
(
TypeError
):
with
ignore
(
TypeError
):
len
(
5
)
def
test_multiple_exception_args
(
self
):
with
ignore
d
(
ZeroDivisionError
,
TypeError
):
with
ignore
(
ZeroDivisionError
,
TypeError
):
len
(
5
)
def
test_exception_hierarchy
(
self
):
with
ignore
d
(
LookupError
):
with
ignore
(
LookupError
):
'Hello'
[
50
]
class
TestRedirectStdout
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
1254b407
...
...
@@ -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
.
ignore
d
().
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment