[Pyrex] Broken 'try/except Foo:' handling

John Arbash Meinel john at arbash-meinel.com
Wed May 19 18:49:44 CEST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Recent versions of Pyrex seem to have broken the syntax of:

 try:
  do_something
 except Exception:
  do_something_else

Specifically, they seem to leave the exception state set (PyErr_Occurred
evaluates to true) in the do_something_else block. Note that doing:

 try:
  do_something
 except Exception, e:
  do_something_else

Succeeds.

I've written a small script which demonstrates this (attached). The two
functions are identical except the ", e:" exception.

The one without ", e:" raises a KeyError during the equality comparison.

In the short term, we can probably work around this bug by changing all
of our exception catching to setting the exception to a variable.
However, I'm pretty certain this is obviously a bug.

I'm sure it is broken w/ Pyrex 0.9.9, I think somebody reported it
broken in 0.9.8.6. If it was 0.9.8.6, then I suspect this change to be
at fault:
  - Scope problem with extension types declared in pxd. [KS Sreeram]

Otherwise, this 0.9.9 change looks suspicious:
  - Exceptions caught by an except clause are no longer put into the thread
    state and cannot be retrieved using sys.exc_info(). To access the caught
    exception, it must be bound to a name in the except clause. A third name
    can be supplied to capture the traceback.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkv0FqgACgkQJdeBCYSNAAMW3wCgwr+5RszNAXY8NMUPcZlleMBI
8l8An1+IECwUTG4CLVPO/+9sG7cmuodt
=Oli9
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pyrex_test.pyx
URL: <http://lists.copyleft.no/pipermail/pyrex/attachments/20100519/5cf31610/attachment.ksh>


More information about the Pyrex mailing list