mirror of
https://github.com/python/cpython.git
synced 2025-12-10 02:50:09 +00:00
Issue #22619: Added negative limit support in the traceback module.
Based on patch by Dmitry Kazakov.
This commit is contained in:
parent
9a578d9ee6
commit
24559e4834
5 changed files with 170 additions and 27 deletions
|
|
@ -1,8 +1,9 @@
|
|||
"""Extract, format and print information about Python stack traces."""
|
||||
|
||||
import collections
|
||||
import itertools
|
||||
import linecache
|
||||
import sys
|
||||
import operator
|
||||
|
||||
__all__ = ['extract_stack', 'extract_tb', 'format_exception',
|
||||
'format_exception_only', 'format_list', 'format_stack',
|
||||
|
|
@ -315,12 +316,17 @@ class StackSummary(list):
|
|||
"""
|
||||
if limit is None:
|
||||
limit = getattr(sys, 'tracebacklimit', None)
|
||||
if limit is not None and limit < 0:
|
||||
limit = 0
|
||||
if limit is not None:
|
||||
if limit >= 0:
|
||||
frame_gen = itertools.islice(frame_gen, limit)
|
||||
else:
|
||||
frame_gen = collections.deque(frame_gen, maxlen=-limit)
|
||||
|
||||
result = klass()
|
||||
fnames = set()
|
||||
for pos, (f, lineno) in enumerate(frame_gen):
|
||||
if limit is not None and pos >= limit:
|
||||
break
|
||||
for f, lineno in frame_gen:
|
||||
co = f.f_code
|
||||
filename = co.co_filename
|
||||
name = co.co_name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue