[Python-ideas] except expression
Steven D'Aprano
steve at pearwood.info
Wed Feb 19 00:27:06 CET 2014
On Tue, Feb 18, 2014 at 02:07:43PM +0000, Paul Moore wrote:
> Also, "expr except fallback" is a very simple case of a keyword-based
> binary operation. So (ignoring the bare except issue) it's much less
> controversial.
But you can't ignore that issue. That issue is *critical* to why it is
a simple binary operation.
I think I would almost prefer the status quo of no except-expression
than one which encourages people to implicitly catch all exceptions.
Yes, for a trivially simple case, it's harmless:
1/x except INFINITY
but you're teaching people bad habits. It doesn't take a much more
complex version to show why it's a bad habit:
1/x + mylits[0] except INFINITY
If not for backwards compatibility, I think bare excepts should be
removed from the language altogether. They are an attractive nuisance. I
don't want to add even more of them. If you truly want to catch
everything, catch BaseException. The fact that this is longer to write
than Exception is a *good thing*. Making it easier to do the wrong thing
is the wrong thing to do.
-1 on bare excepts in the expression form. If that makes it harder to
sell the PEP, oh well, better that than adding a misfeature to the
language.
--
Steven
More information about the Python-ideas
mailing list