Ticket #10548: 10548-coerce-traceback.patch

File 10548-coerce-traceback.patch, 3.6 KB (added by robertwb, 10 years ago)
  • sage/structure/coerce.pyx

    # HG changeset patch
    # User Robert Bradshaw <robertwb@math.washington.edu>
    # Date 1300773512 25200
    # Node ID e9fc12cab2ef5492e499cf1282274bed95a4a11e
    # Parent  029709447b87db93acff1746b570dd975ff12433
    #10548 - stringify coercion tracebacks to avoid memory leaks
    
    diff -r 029709447b87 -r e9fc12cab2ef 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             [(<class 'sage.structure.coerce_exceptions.CoercionException'>, CoercionException(AttributeError("'IdealMonoid_c_with_category' object has no attribute 'base_extend'",),), <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 029709447b87 -r e9fc12cab2ef sage/structure/element.pyx
    a b  
    26622662        TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 5'
    26632663    """
    26642664    if dump:
    2665         for exc_info in coercion_model.exception_stack():
    2666             print ''.join(traceback.format_exception(*exc_info))
     2665        for traceback in coercion_model.exception_stack():
     2666            print traceback
    26672667    else:
    26682668        return coercion_model.exception_stack()
    26692669