mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Issue #20616: Add a format() method to tracemalloc.Traceback.
This commit is contained in:
		
							parent
							
								
									f617fa88de
								
							
						
					
					
						commit
						23f628de4a
					
				
					 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