try..except with empty exceptions
rosuav at gmail.com
Sat Apr 11 13:21:00 CEST 2015
On Sat, Apr 11, 2015 at 9:00 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Yes, I agree that Python's behaviour here is better than the alternative.
> Having "except ()" catch nothing is consistent with the behaviour with
> other tuples, so I'm okay with that. But it still surprised me :-)
It's worth noting that there's another false parallel here. Grouping
nothing creates something.
x = 1 # x is an integer
x = (1) # ditto
x = (((((((((1))))))))) # LITHP
Okay, so adding parentheses does nothing, right? Right.
x = # syntax error
x = () # empty tuple
"Parentheses around nothing" is NOT the same as "nothing". So if you
compare against this, then it makes perfect sense for "except :" and
"except ():" to be distinctly different.
But I agree, it would be very nice if Python 3 could have abolished
the truly confusing part of this, where "except:" catches everything.
Forcing people to spell it "except BaseException:" would fix all of
this. How hard is it to deprecate and then remove that, same as string
exceptions were removed?
You know what, I'm moving that to -ideas.
More information about the Python-list