mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	bpo-37961: Fix regression in tracemalloc.Traceback.__repr__ (GH-23805)
Regression in8d59eb1b66. (cherry picked from commit051b981867) Co-authored-by: Daniel Hahler <git@thequod.de>
This commit is contained in:
		
							parent
							
								
									1662868490
								
							
						
					
					
						commit
						78062e07bc
					
				
					 3 changed files with 22 additions and 1 deletions
				
			
		|  | @ -84,6 +84,25 @@ def traceback_filename(filename): | |||
|     return traceback_lineno(filename, 0) | ||||
| 
 | ||||
| 
 | ||||
| class TestTraceback(unittest.TestCase): | ||||
|     def test_repr(self): | ||||
|         def get_repr(*args) -> str: | ||||
|             return repr(tracemalloc.Traceback(*args)) | ||||
| 
 | ||||
|         self.assertEqual(get_repr(()), "<Traceback ()>") | ||||
|         self.assertEqual(get_repr((), 0), "<Traceback () total_nframe=0>") | ||||
| 
 | ||||
|         frames = (("f1", 1), ("f2", 2)) | ||||
|         exp_repr_frames = ( | ||||
|             "(<Frame filename='f2' lineno=2>," | ||||
|             " <Frame filename='f1' lineno=1>)" | ||||
|         ) | ||||
|         self.assertEqual(get_repr(frames), | ||||
|                          f"<Traceback {exp_repr_frames}>") | ||||
|         self.assertEqual(get_repr(frames, 2), | ||||
|                          f"<Traceback {exp_repr_frames} total_nframe=2>") | ||||
| 
 | ||||
| 
 | ||||
| class TestTracemallocEnabled(unittest.TestCase): | ||||
|     def setUp(self): | ||||
|         if tracemalloc.is_tracing(): | ||||
|  | @ -1064,6 +1083,7 @@ def test_stop_untrack(self): | |||
| 
 | ||||
| def test_main(): | ||||
|     support.run_unittest( | ||||
|         TestTraceback, | ||||
|         TestTracemallocEnabled, | ||||
|         TestSnapshot, | ||||
|         TestFilters, | ||||
|  |  | |||
|  | @ -226,7 +226,7 @@ def __str__(self): | |||
|         return str(self[0]) | ||||
| 
 | ||||
|     def __repr__(self): | ||||
|         s = "<Traceback %r" % tuple(self) | ||||
|         s = f"<Traceback {tuple(self)}" | ||||
|         if self._total_nframe is None: | ||||
|             s += ">" | ||||
|         else: | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| Fix crash in :func:`tracemalloc.Traceback.__repr__` (regressed in Python 3.9). | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)