#71: Better tracebacks
-------------------------------------+-------------------------------------
       Reporter:  Justin Walker      |        Owner:  cwitty
  (justin@…                          |       Status:  new
           Type:  enhancement        |    Milestone:  sage-6.5
       Priority:  minor              |   Resolution:
      Component:  misc               |    Merged in:
       Keywords:                     |    Reviewers:
        Authors:  Jeroen Demeyer     |  Work issues:
Report Upstream:  N/A                |       Commit:
         Branch:                     |  99003530ae42e5ddbc96d1516d3f27a779bdfecb
  u/jdemeyer/ticket/71               |     Stopgaps:
   Dependencies:  #17382             |
-------------------------------------+-------------------------------------
Changes (by jdemeyer):

 * dependencies:   => #17382
 * upstream:  Not yet reported upstream; Will do shortly. => N/A


Old description:

> When a .sage file is "load"ed or "attach"ed, it gets translated to a .py
> file before being processed; the result is a file with different
> structure than the original.  Any errors are described in terms of the
> .py file, not the .sage file.
>
> One working solution is to monkey-patch `traceback.extract_tb()` to undo
> preparsing.
>
> Since we're messing with tracebacks anyway, this patch will also fix
> tracebacks for Cython files. This requires an upstream patch.
>
> The traceback below was generated with this patch. It shows the
> unpreparsed {{{1/0}}} and it also shows the Cython source:
> {{{
> sage: 1/0
> ---------------------------------------------------------------------------
> ZeroDivisionError                         Traceback (most recent call
> last)
> <ipython-input-1-3cdd7c9e2324> in <module>()
> ----> 1 1/0
>
> /usr/local/src/sage-config/sage/structure/element.pyx in
> sage.structure.element.RingElement.__div__
> (build/cythonized/sage/structure/element.c:17829)()
>    1891                 return
> (<RingElement>self)._idiv_(<RingElement>right)
>    1892             else:
> -> 1893                 return
> (<RingElement>self)._div_(<RingElement>right)
>    1894         global coercion_model
>    1895         return coercion_model.bin_op(self, right, div)
>
> /usr/local/src/sage-config/sage/rings/integer.pyx in
> sage.rings.integer.Integer._div_
> (build/cythonized/sage/rings/integer.c:12964)()
>    1795         # This is vastly faster than doing it here, since here
>    1796         # we can't cimport rationals.
> -> 1797         return the_integer_ring._div(self, right)
>    1798
>    1799     def __floordiv__(x, y):
>
> /usr/local/src/sage-config/sage/rings/integer_ring.pyx in
> sage.rings.integer_ring.IntegerRing_class._div
> (build/cythonized/sage/rings/integer_ring.c:4578)()
>     443         cdef rational.Rational x = PY_NEW(rational.Rational)
>     444         if mpz_sgn(right.value) == 0:
> --> 445             raise ZeroDivisionError, 'Rational division by zero'
>     446         mpz_set(mpq_numref(x.value), left.value)
>     447         mpz_set(mpq_denref(x.value), right.value)
>
> ZeroDivisionError: Rational division by zero
> }}}

New description:

 When a .sage file is "load"ed or "attach"ed, it gets translated to a .py
 file before being processed; the result is a file with different structure
 than the original.  Any errors are described in terms of the .py file, not
 the .sage file.

 One working solution is to monkey-patch `traceback.extract_tb()` to undo
 preparsing.

 The traceback below was generated with this patch. It shows the
 unpreparsed {{{1/0}}} and it also shows the Cython source (see #17382):
 {{{
 sage: 1/0
 ---------------------------------------------------------------------------
 ZeroDivisionError                         Traceback (most recent call
 last)
 <ipython-input-1-3cdd7c9e2324> in <module>()
 ----> 1 1/0

 /usr/local/src/sage-config/sage/structure/element.pyx in
 sage.structure.element.RingElement.__div__
 (build/cythonized/sage/structure/element.c:17829)()
    1891                 return
 (<RingElement>self)._idiv_(<RingElement>right)
    1892             else:
 -> 1893                 return
 (<RingElement>self)._div_(<RingElement>right)
    1894         global coercion_model
    1895         return coercion_model.bin_op(self, right, div)

 /usr/local/src/sage-config/sage/rings/integer.pyx in
 sage.rings.integer.Integer._div_
 (build/cythonized/sage/rings/integer.c:12964)()
    1795         # This is vastly faster than doing it here, since here
    1796         # we can't cimport rationals.
 -> 1797         return the_integer_ring._div(self, right)
    1798
    1799     def __floordiv__(x, y):

 /usr/local/src/sage-config/sage/rings/integer_ring.pyx in
 sage.rings.integer_ring.IntegerRing_class._div
 (build/cythonized/sage/rings/integer_ring.c:4578)()
     443         cdef rational.Rational x = PY_NEW(rational.Rational)
     444         if mpz_sgn(right.value) == 0:
 --> 445             raise ZeroDivisionError, 'Rational division by zero'
     446         mpz_set(mpq_numref(x.value), left.value)
     447         mpz_set(mpq_denref(x.value), right.value)

 ZeroDivisionError: Rational division by zero
 }}}

--

--
Ticket URL: <http://trac.sagemath.org/ticket/71#comment:19>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to