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
c31e6227
Commit
c31e6227
authored
Sep 29, 2014
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#17442: Add chained traceback support to InteractiveInterpreter.
Patch by Claudiu Popa.
parent
4d75a017
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
12 deletions
+70
-12
Doc/library/code.rst
Doc/library/code.rst
+3
-0
Doc/whatsnew/3.5.rst
Doc/whatsnew/3.5.rst
+7
-0
Lib/code.py
Lib/code.py
+22
-12
Lib/test/test_code_module.py
Lib/test/test_code_module.py
+35
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/code.rst
View file @
c31e6227
...
...
@@ -114,6 +114,9 @@ Interactive Interpreter Objects
because it is within the interpreter object implementation. The output is
written by the :meth:`write` method.
.. versionchanged:: 3.5 The full chained traceback is displayed instead
of just the primary traceback.
.. method:: InteractiveInterpreter.write(data)
...
...
Doc/whatsnew/3.5.rst
View file @
c31e6227
...
...
@@ -134,6 +134,13 @@ New Modules
Improved Modules
================
code
----
* The :func:`code.InteractiveInterpreter.showtraceback` method now prints
the full chained traceback, just like the interactive interpreter
(contributed by Claudiu.Popa in :issue:`17442`).
compileall
----------
...
...
Lib/code.py
View file @
c31e6227
...
...
@@ -137,25 +137,35 @@ class InteractiveInterpreter:
The output is written by self.write(), below.
"""
sys
.
last_type
,
sys
.
last_value
,
last_tb
=
ei
=
sys
.
exc_info
()
sys
.
last_traceback
=
last_tb
try
:
type
,
value
,
tb
=
sys
.
exc_info
()
sys
.
last_type
=
type
sys
.
last_value
=
value
sys
.
last_traceback
=
tb
tblist
=
traceback
.
extract_tb
(
tb
)
del
tblist
[:
1
]
lines
=
traceback
.
format_list
(
tblist
)
if
lines
:
lines
.
insert
(
0
,
"Traceback (most recent call last):
\
n
"
)
lines
.
extend
(
traceback
.
format_exception_only
(
type
,
value
))
lines
=
[]
for
value
,
tb
in
traceback
.
_iter_chain
(
*
ei
[
1
:]):
if
isinstance
(
value
,
str
):
lines
.
append
(
value
)
lines
.
append
(
'
\
n
'
)
continue
if
tb
:
tblist
=
traceback
.
extract_tb
(
tb
)
if
tb
is
last_tb
:
# The last traceback includes the frame we
# exec'd in
del
tblist
[:
1
]
tblines
=
traceback
.
format_list
(
tblist
)
if
tblines
:
lines
.
append
(
"Traceback (most recent call last):
\
n
"
)
lines
.
extend
(
tblines
)
lines
.
extend
(
traceback
.
format_exception_only
(
type
(
value
),
value
))
finally
:
tblist
=
tb
=
None
tblist
=
last_tb
=
ei
=
None
if
sys
.
excepthook
is
sys
.
__excepthook__
:
self
.
write
(
''
.
join
(
lines
))
else
:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
sys
.
excepthook
(
type
,
value
,
tb
)
sys
.
excepthook
(
type
,
value
,
last_
tb
)
def
write
(
self
,
data
):
"""Write a string.
...
...
Lib/test/test_code_module.py
View file @
c31e6227
"Test InteractiveConsole and InteractiveInterpreter from code module"
import
sys
import
unittest
from
textwrap
import
dedent
from
contextlib
import
ExitStack
from
unittest
import
mock
from
test
import
support
...
...
@@ -78,6 +79,40 @@ class TestInteractiveConsole(unittest.TestCase):
self
.
console
.
interact
(
banner
=
''
)
self
.
assertEqual
(
len
(
self
.
stderr
.
method_calls
),
1
)
def
test_cause_tb
(
self
):
self
.
infunc
.
side_effect
=
[
"raise ValueError('') from AttributeError"
,
EOFError
(
'Finished'
)]
self
.
console
.
interact
()
output
=
''
.
join
(
''
.
join
(
call
[
1
])
for
call
in
self
.
stderr
.
method_calls
)
expected
=
dedent
(
"""
AttributeError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ValueError
"""
)
self
.
assertIn
(
expected
,
output
)
def
test_context_tb
(
self
):
self
.
infunc
.
side_effect
=
[
"try: ham
\
n
except: eggs
\
n
"
,
EOFError
(
'Finished'
)]
self
.
console
.
interact
()
output
=
''
.
join
(
''
.
join
(
call
[
1
])
for
call
in
self
.
stderr
.
method_calls
)
expected
=
dedent
(
"""
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'ham' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 2, in <module>
NameError: name 'eggs' is not defined
"""
)
self
.
assertIn
(
expected
,
output
)
def
test_main
():
support
.
run_unittest
(
TestInteractiveConsole
)
...
...
Misc/NEWS
View file @
c31e6227
...
...
@@ -145,6 +145,9 @@ Core and Builtins
Library
-------
-
Issue
#
17442
:
InteractiveInterpreter
now
displays
the
full
chained
traceback
in
its
showtraceback
method
,
to
match
the
built
in
interactive
interpreter
.
-
Issue
#
10510
:
distutils
register
and
upload
methods
now
use
HTML
standards
compliant
CRLF
line
endings
.
...
...
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