Broken 'try/except Foo:' handling
John Arbash Meinel <[email protected]> Wed, 19 May 2010 11:49:44 -0500
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------030305070007030505070307
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
-----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-----
--------------030305070007030505070307
Content-Type: text/plain;
name="pyrex_test.pyx"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="pyrex_test.pyx"
CiMgQnVnIGluIHJlY2VudCB2ZXJzaW9ucyBvZiBweXJleCAocHJvYmFibHkgMC45LjguNiwg
ZGVmaW5pdGVseSAwLjkuOSkKCiMgVGhlICdqdXN0X3R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ICB0cmFwX2FuZF9jYXRj
aCgxKQogICAgZXhjZXB0IEtleUVycm9yLCBlOgogICAgICAgIHByaW50ICd0cmFwX2FuZF9j
YXRjaCByYWlzZWQgYSBrZXkgZXJyb3IsIGJ1dCBzaG91bGRuXCd0IGhhdmUgOignCiAgICBl
bHNlOgogICAgICAgIHByaW50ICd0cmFwX2FuZF9jYXRjaCB3b3JrZWQgYXMgZXhwZWN0ZWQn
Cg==
--------------030305070007030505070307
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
_______________________________________________
Pyrex mailing list
[email protected]
http://lists.copyleft.no/mailman/listinfo/pyrex
--------------030305070007030505070307--