Ticket #10548: 10548-coerce-traceback.2.patch

File 10548-coerce-traceback.2.patch, 3.5 KB (added by mderickx, 2 years ago)

rebased against 4.7.alpha1

  • sage/structure/coerce.pyx

    # HG changeset patch
    # User Robert Bradshaw <robertwb@math.washington.edu>
    # Date 1300773512 25200
    # Node ID 6d25566e4ad5847b615ccdaf9a2af0bedd3a563d
    # Parent  9326be5cb9fac428116d39803e47b94376abafef
    #10548 - stringify coercion tracebacks to avoid memory leaks
    
    diff -r 9326be5cb9fa -r 6d25566e4ad5 sage/structure/coerce.pyx
    a b  
    8888from parent import Set_PythonType 
    8989from coerce_exceptions import CoercionException 
    9090 
    91 import sys 
     91import sys, traceback 
    9292 
    9393from coerce_actions import LeftModuleAction, RightModuleAction, IntegerMulAction 
    9494 
     
    295295            [] 
    296296            sage: cm._test_exception_stack() 
    297297            sage: cm.exception_stack() 
    298             [(<type 'exceptions.TypeError'>,  TypeError('just a test',),  <traceback object at ...>)] 
     298            ['Traceback (most recent call last):\n  File "coerce.pyx", line ...TypeError: just a test'] 
    299299 
    300             The function _test_exception_stack is executing the following code: 
     300        The function _test_exception_stack is executing the following code:: 
     301             
    301302            try: 
    302303                raise TypeError, "just a test" 
    303304            except: 
     
    306307        if not self._exceptions_cleared: 
    307308            self._exception_stack = [] 
    308309            self._exceptions_cleared = True 
    309         self._exception_stack.append(sys.exc_info()) 
     310        self._exception_stack.append(traceback.format_exc().strip()) 
    310311 
    311312    def _test_exception_stack(self): 
    312         """ 
     313        r""" 
    313314        A function to test the exception stack. 
    314315         
    315316        EXAMPLES:: 
     
    321322            [] 
    322323            sage: cm._test_exception_stack() 
    323324            sage: cm.exception_stack() 
    324             [(<type 'exceptions.TypeError'>,  TypeError('just a test',),  <traceback object at ...>)] 
     325            ['Traceback (most recent call last):\n  File "coerce.pyx", line ...TypeError: just a test'] 
    325326        """ 
    326327        try: 
    327328            raise TypeError, "just a test" 
     
    355356         
    356357            sage: import traceback 
    357358            sage: cm.exception_stack() 
    358             [(<type 'exceptions.TypeError'>, TypeError('No coercion from Rational Field to pushout Ring of integers modulo 1',), <traceback object at ...>), (<type 'exceptions.TypeError'>, TypeError("no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 3'",), <traceback object at ...>)] 
    359             sage: print ''.join(sum([traceback.format_exception(*info) for info in cm.exception_stack()], [])) 
     359            ['Traceback (most recent call last):...', 'Traceback (most recent call last):...'] 
     360            sage: print cm.exception_stack()[-1] 
    360361            Traceback (most recent call last): 
    361362            ... 
    362363            TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 3' 
  • sage/structure/element.pyx

    diff -r 9326be5cb9fa -r 6d25566e4ad5 sage/structure/element.pyx
    a b  
    26842684        TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 5' 
    26852685    """ 
    26862686    if dump: 
    2687         for exc_info in coercion_model.exception_stack(): 
    2688             print ''.join(traceback.format_exception(*exc_info)) 
     2687        for traceback in coercion_model.exception_stack(): 
     2688            print traceback 
    26892689    else: 
    26902690        return coercion_model.exception_stack() 
    26912691