[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Wed Feb 19 04:05:09 CET 2014


On Wed, Feb 19, 2014 at 1:55 PM, MRAB <python at mrabarnett.plus.com> wrote:
> On the one hand, allowing a bare except would be consistent with the
> statement form.
>
> On the other hand, without the ability to re-raise, it's just asking
> for trouble, although there _is_ that "consenting adults" thing! :-)

Regardless of the ability to re-raise, I wouldn't be against
disallowing a bare except, and insisting that it be spelled "except
BaseException:" instead. The main argument against that is
consistency; in fact, possibly the *only* viable argument against
that. Obviously backward compatibility is a strong reason to keep
support in the statement form, but how important is it to be
consistent with something that's strongly discouraged anyway?

Hmm. Actually, how strongly *is* the bare except discouraged? There
are a good lot of them in the stdlib, and quite a few probably should
be "except Exception" anyway. Currently, PEP 8 permits two use-cases
(log and continue, and clean-up and reraise), but then maybe
discourages one of them. Core devs, what's your opinion on new code
with "except:" in it? Would you prefer to see it spelled "except
BaseException:"?

ChrisA


More information about the Python-ideas mailing list