mirror of
https://github.com/python/cpython.git
synced 2025-07-27 21:24:32 +00:00
Issue #20616: Add a format() method to tracemalloc.Traceback.
This commit is contained in:
parent
34c1540009
commit
a91ff1423f
4 changed files with 59 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
|||
from collections import Sequence
|
||||
from functools import total_ordering
|
||||
import fnmatch
|
||||
import linecache
|
||||
import os.path
|
||||
import pickle
|
||||
|
||||
|
@ -205,6 +206,18 @@ class Traceback(Sequence):
|
|||
def __repr__(self):
|
||||
return "<Traceback %r>" % (tuple(self),)
|
||||
|
||||
def format(self, limit=None):
|
||||
lines = []
|
||||
if limit is not None and limit < 0:
|
||||
return lines
|
||||
for frame in self[:limit]:
|
||||
lines.append(' File "%s", line %s'
|
||||
% (frame.filename, frame.lineno))
|
||||
line = linecache.getline(frame.filename, frame.lineno).strip()
|
||||
if line:
|
||||
lines.append(' %s' % line)
|
||||
return lines
|
||||
|
||||
|
||||
def get_object_traceback(obj):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue