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
bb52d69c
Commit
bb52d69c
authored
Jan 24, 2014
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Plain Diff
Merge removal of issue 20317 debugging code from 3.3
parents
6559d41e
be48325f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
13 deletions
+49
-13
Lib/contextlib.py
Lib/contextlib.py
+1
-3
Lib/test/test_contextlib.py
Lib/test/test_contextlib.py
+48
-10
No files found.
Lib/contextlib.py
View file @
bb52d69c
...
...
@@ -298,7 +298,7 @@ class ExitStack(object):
# we were actually nesting multiple with statements
frame_exc
=
sys
.
exc_info
()[
1
]
def
_fix_exception_context
(
new_exc
,
old_exc
):
# Context
isn't what we wan
t, so find the end of the chain
# Context
may not be correc
t, so find the end of the chain
while
1
:
exc_context
=
new_exc
.
__context__
if
exc_context
is
old_exc
:
...
...
@@ -306,8 +306,6 @@ class ExitStack(object):
return
if
exc_context
is
None
or
exc_context
is
frame_exc
:
break
details
=
id
(
new_exc
),
id
(
old_exc
),
id
(
exc_context
)
raise
Exception
(
str
(
details
))
new_exc
=
exc_context
# Change the end of the chain to point to the exception
# we expect it to reference
...
...
Lib/test/test_contextlib.py
View file @
bb52d69c
...
...
@@ -629,24 +629,62 @@ class TestExitStack(unittest.TestCase):
def
test_exit_exception_with_correct_context
(
self
):
# http://bugs.python.org/issue20317
@
contextmanager
def
gets_the_context_right
():
def
gets_the_context_right
(
exc
):
try
:
yield
6
yield
finally
:
1
/
0
raise
exc
exc1
=
Exception
(
1
)
exc2
=
Exception
(
2
)
exc3
=
Exception
(
3
)
exc4
=
Exception
(
4
)
# The contextmanager already fixes the context, so prior to the
# fix, ExitStack would try to fix it *again* and get into an
# infinite self-referential loop
try
:
with
ExitStack
()
as
stack
:
stack
.
enter_context
(
gets_the_context_right
())
stack
.
enter_context
(
gets_the_context_right
())
stack
.
enter_context
(
gets_the_context_right
())
except
ZeroDivisionError
as
exc
:
self
.
assertIsInstance
(
exc
.
__context__
,
ZeroDivisionError
)
self
.
assertIsInstance
(
exc
.
__context__
.
__context__
,
ZeroDivisionError
)
self
.
assertIsNone
(
exc
.
__context__
.
__context__
.
__context__
)
stack
.
enter_context
(
gets_the_context_right
(
exc4
))
stack
.
enter_context
(
gets_the_context_right
(
exc3
))
stack
.
enter_context
(
gets_the_context_right
(
exc2
))
raise
exc1
except
Exception
as
exc
:
self
.
assertIs
(
exc
,
exc4
)
self
.
assertIs
(
exc
.
__context__
,
exc3
)
self
.
assertIs
(
exc
.
__context__
.
__context__
,
exc2
)
self
.
assertIs
(
exc
.
__context__
.
__context__
.
__context__
,
exc1
)
self
.
assertIsNone
(
exc
.
__context__
.
__context__
.
__context__
.
__context__
)
def
test_exit_exception_with_existing_context
(
self
):
# Addresses a lack of test coverage discovered after checking in a
# fix for issue 20317 that still contained debugging code.
def
raise_nested
(
inner_exc
,
outer_exc
):
try
:
raise
inner_exc
finally
:
raise
outer_exc
exc1
=
Exception
(
1
)
exc2
=
Exception
(
2
)
exc3
=
Exception
(
3
)
exc4
=
Exception
(
4
)
exc5
=
Exception
(
5
)
try
:
with
ExitStack
()
as
stack
:
stack
.
callback
(
raise_nested
,
exc4
,
exc5
)
stack
.
callback
(
raise_nested
,
exc2
,
exc3
)
raise
exc1
except
Exception
as
exc
:
self
.
assertIs
(
exc
,
exc5
)
self
.
assertIs
(
exc
.
__context__
,
exc4
)
self
.
assertIs
(
exc
.
__context__
.
__context__
,
exc3
)
self
.
assertIs
(
exc
.
__context__
.
__context__
.
__context__
,
exc2
)
self
.
assertIs
(
exc
.
__context__
.
__context__
.
__context__
.
__context__
,
exc1
)
self
.
assertIsNone
(
exc
.
__context__
.
__context__
.
__context__
.
__context__
.
__context__
)
def
test_body_exception_suppress
(
self
):
...
...
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