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
da2268fe
Commit
da2268fe
authored
Apr 24, 2006
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix contextlib.nested to cope with exit methods raising and handling exceptions
parent
27ec1a77
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletion
+33
-1
Lib/contextlib.py
Lib/contextlib.py
+4
-1
Lib/test/test_contextlib.py
Lib/test/test_contextlib.py
+23
-0
Misc/NEWS
Misc/NEWS
+6
-0
No files found.
Lib/contextlib.py
View file @
da2268fe
...
...
@@ -127,7 +127,10 @@ def nested(*contexts):
except
:
exc
=
sys
.
exc_info
()
if
exc
!=
(
None
,
None
,
None
):
raise
# Don't rely on sys.exc_info() still containing
# the right information. Another exception may
# have been raised and caught by an exit method
raise
exc
[
0
],
exc
[
1
],
exc
[
2
]
@
contextmanager
...
...
Lib/test/test_contextlib.py
View file @
da2268fe
...
...
@@ -146,6 +146,29 @@ class NestedTestCase(unittest.TestCase):
else
:
self
.
fail
(
"Didn't raise ZeroDivisionError"
)
def
test_nested_right_exception
(
self
):
state
=
[]
@
contextmanager
def
a
():
yield
1
class
b
(
object
):
def
__enter__
(
self
):
return
2
def
__exit__
(
self
,
*
exc_info
):
try
:
raise
Exception
()
except
:
pass
try
:
with
nested
(
a
(),
b
())
as
(
x
,
y
):
1
/
0
except
ZeroDivisionError
:
self
.
assertEqual
((
x
,
y
),
(
1
,
2
))
except
Exception
:
self
.
fail
(
"Reraised wrong exception"
)
else
:
self
.
fail
(
"Didn't raise ZeroDivisionError"
)
def
test_nested_b_swallows
(
self
):
@
contextmanager
def
a
():
...
...
Misc/NEWS
View file @
da2268fe
...
...
@@ -86,6 +86,9 @@ Extension Modules
Library
-------
- Fixed contextlib.nested to cope with exceptions being raised and
caught inside exit handlers.
- Updated optparse module to Optik 1.5.1 (allow numeric constants in
hex, octal, or binary; add ``append_const`` action; keep going if
gettext cannot be imported; added ``OptionParser.destroy()`` method;
...
...
@@ -158,6 +161,9 @@ C API
Tests
-----
-
test_contextlib
now
checks
contextlib
.
nested
can
cope
with
exceptions
being
raised
and
caught
inside
exit
handlers
.
-
test_cmd_line
now
checks
operation
of
the
-
m
and
-
c
command
switches
-
The
test_contextlib
test
in
2.5
a1
wasn
't actually run unless you ran
...
...
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