This was driving me crazy... There is either a bug or a very subtle
difference in exception semantics between python and pyrex. This is
demonstrated by the following python code:

-----------------
try:
    raise TypeError
except  TypeError:
    print "A"
    QQ.has_coerce_map_from(ZZ)
    print "B"
    raise
-----------------

Before you run it, try to guess what it will do (hint: it will raise
an exception, but... which type? what will be printed before the
exception?)

Now run it *from a clean, just started sage session*, and see what
happens. Run it another time; the bug will only bite in the *first*
try for each sage session.
Actually, you can change QQ by e.g. QQ[x] and get a different
exception, etc. but only the first time.

If you guessed what's going on: QQ.has_coerce_map_from(ZZ) ends up
calling a pyrex c function, which (only the first time) raises and
catches an exception. Apparently, it is not scoping its "current
exception", but rather using the caller's!!

Note that if you define a python function which raises and catches
exceptions, it does NOT modify the "current exception" in the caller.

Best, Gonzalo

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to