Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e02a301

Browse files
committed
Third to last example is now marked as a test, but I can't actually test
it yet since sphinx can't run the doctests using python3. Merged revisions 72038 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r72038 | r.david.murray | 2009-04-27 13:22:36 -0400 (Mon, 27 Apr 2009) | 8 lines Make sys.xxx variable references into links, note that print_last only works when an exception gets to the interactive prompt, and update the examples after testing. The last one is now a valid Sphinx doctest, but of the preceding two one can't be made a doctest and the other one I'm postponing to 3.x because sphinx handles doctests as Unicode strings and that makes the 2.x output confusing. ........
1 parent 7b2669b commit e02a301

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

Doc/library/traceback.rst

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interpreter.
1414
.. index:: object: traceback
1515

1616
The module uses traceback objects --- this is the object type that is stored in
17-
the ``sys.last_traceback`` variable and returned as the third item from
17+
the :data:`sys.last_traceback` variable and returned as the third item from
1818
:func:`sys.exc_info`.
1919

2020
The module defines the following functions:
@@ -55,7 +55,8 @@ The module defines the following functions:
5555
.. function:: print_last([limit[, file[, chain]]])
5656

5757
This is a shorthand for ``print_exception(sys.last_type, sys.last_value,
58-
sys.last_traceback, limit, file)``.
58+
sys.last_traceback, limit, file)``. In general it will work only after
59+
an exception has reached an interactive prompt (see :data:`sys.last_type`).
5960

6061

6162
.. function:: print_stack([f[, limit[, file]]])
@@ -157,7 +158,9 @@ module. ::
157158

158159

159160
The following example demonstrates the different ways to print and format the
160-
exception and traceback::
161+
exception and traceback:
162+
163+
.. testcode::
161164

162165
import sys, traceback
163166

@@ -190,54 +193,47 @@ exception and traceback::
190193
print("*** format_tb:")
191194
print(repr(traceback.format_tb(exceptionTraceback)))
192195
print("*** tb_lineno:", traceback.tb_lineno(exceptionTraceback))
193-
print("*** print_last:")
194-
traceback.print_last()
195196

197+
The output for the example would look similar to this:
196198

197-
The output for the example would look similar to this::
199+
.. testoutput::
200+
:options: +NORMALIZE_WHITESPACE
198201

199202
*** print_tb:
200-
File "<doctest>", line 9, in <module>
203+
File "<doctest...>", line 10, in <module>
201204
lumberjack()
202205
*** print_exception:
203206
Traceback (most recent call last):
204-
File "<doctest>", line 9, in <module>
207+
File "<doctest...>", line 10, in <module>
205208
lumberjack()
206-
File "<doctest>", line 3, in lumberjack
209+
File "<doctest...>", line 4, in lumberjack
207210
bright_side_of_death()
208211
IndexError: tuple index out of range
209212
*** print_exc:
210213
Traceback (most recent call last):
211-
File "<doctest>", line 9, in <module>
214+
File "<doctest...>", line 10, in <module>
212215
lumberjack()
213-
File "<doctest>", line 3, in lumberjack
216+
File "<doctest...>", line 4, in lumberjack
214217
bright_side_of_death()
215218
IndexError: tuple index out of range
216219
*** format_exc, first and last line:
217220
Traceback (most recent call last):
218221
IndexError: tuple index out of range
219222
*** format_exception:
220223
['Traceback (most recent call last):\n',
221-
' File "<doctest>", line 9, in <module>\n lumberjack()\n',
222-
' File "<doctest>", line 3, in lumberjack\n bright_side_of_death()\n',
223-
' File "<doctest>", line 6, in bright_side_of_death\n return tuple()[0]\n',
224+
' File "<doctest...>", line 10, in <module>\n lumberjack()\n',
225+
' File "<doctest...>", line 4, in lumberjack\n bright_side_of_death()\n',
226+
' File "<doctest...>", line 7, in bright_side_of_death\n return tuple()[0]\n',
224227
'IndexError: tuple index out of range\n']
225228
*** extract_tb:
226-
[('<doctest>', 9, '<module>', 'lumberjack()'),
227-
('<doctest>', 3, 'lumberjack', 'bright_side_of_death()'),
228-
('<doctest>', 6, 'bright_side_of_death', 'return tuple()[0]')]
229+
[('<doctest...>', 10, '<module>', 'lumberjack()'),
230+
('<doctest...>', 4, 'lumberjack', 'bright_side_of_death()'),
231+
(u'<doctest...>', 7, 'bright_side_of_death', 'return tuple()[0]')]
229232
*** format_tb:
230-
[' File "<doctest>", line 9, in <module>\n lumberjack()\n',
231-
' File "<doctest>", line 3, in lumberjack\n bright_side_of_death()\n',
232-
' File "<doctest>", line 6, in bright_side_of_death\n return tuple()[0]\n']
233-
*** tb_lineno: 2
234-
*** print_last:
235-
Traceback (most recent call last):
236-
File "<doctest>", line 9, in <module>
237-
lumberjack()
238-
File "<doctest>", line 3, in lumberjack
239-
bright_side_of_death()
240-
IndexError: tuple index out of range
233+
[' File "<doctest...>", line 10, in <module>\n lumberjack()\n',
234+
' File "<doctest...>", line 4, in lumberjack\n bright_side_of_death()\n',
235+
' File "<doctest...>", line 7, in bright_side_of_death\n return tuple()[0]\n']
236+
*** tb_lineno: 10
241237

242238

243239
The following example shows the different ways to print and format the stack::
@@ -266,7 +262,10 @@ The following example shows the different ways to print and format the stack::
266262
' File "<doctest>", line 8, in lumberstack\n print(repr(traceback.format_stack()))\n']
267263

268264

269-
This last example demonstrates the final few formatting functions::
265+
This last example demonstrates the final few formatting functions:
266+
267+
.. doctest::
268+
:options: +NORMALIZE_WHITESPACE
270269

271270
>>> import traceback
272271
>>> traceback.format_list([('spam.py', 3, '<module>', 'spam.eggs()'),

0 commit comments

Comments
 (0)