mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	Correct one of the "MemoryError oddities":
the traceback would grow each time a MemoryError is raised.
This commit is contained in:
		
							parent
							
								
									a986dfa927
								
							
						
					
					
						commit
						e19cadb427
					
				
					 2 changed files with 28 additions and 0 deletions
				
			
		|  | @ -596,6 +596,24 @@ class MyException(Exception, metaclass=Meta): | |||
|                          "Exception ValueError: ValueError() " | ||||
|                          "in <class 'KeyError'> ignored\n") | ||||
| 
 | ||||
| 
 | ||||
|     def test_MemoryError(self): | ||||
|         # PyErr_NoMemory always raises the same exception instance. | ||||
|         # Check that the traceback is not doubled. | ||||
|         import traceback | ||||
|         def raiseMemError(): | ||||
|             try: | ||||
|                 "a" * (sys.maxsize // 2) | ||||
|             except MemoryError as e: | ||||
|                 tb = e.__traceback__ | ||||
|             else: | ||||
|                 self.fail("Should have raises a MemoryError") | ||||
|             return traceback.format_tb(tb) | ||||
| 
 | ||||
|         tb1 = raiseMemError() | ||||
|         tb2 = raiseMemError() | ||||
|         self.assertEqual(tb1, tb2) | ||||
| 
 | ||||
| def test_main(): | ||||
|     run_unittest(ExceptionTests) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Amaury Forgeot d'Arc
						Amaury Forgeot d'Arc