[Python-Dev] Bare except clauses in PEP 348

Raymond Hettinger raymond.hettinger at verizon.net
Thu Aug 25 15:03:36 CEST 2005


> > Efforts to improve Py3.0 have spilled
> > over into breaking Py2.x code with no compensating benefits. [...]
> > We don't have to wreck 2.x in order to make 3.0 better.
> 
> I think you're overstating things a bit here.

It's only an overstatement if Guido didn't mean what he said.  If bare
except clauses are deprecated in 2.x, it WILL affect tons of existing
code and invalidate a portion of almost all Python books.



> > Remember, the ONLY benefit from the whole PEP is that in 3.0, it
will no
> > longer be necessary to write "except (KeyError, SystemExit):
raise".
> > [...] IOW, there's nothing worth inflicting destruction on tons of
> > 2.x code.
> 
> And now I *KNOW* you're overstating things. There are LOTS of benefits
> to the PEP in 3.0. My own personal favorite is that users can be
> guaranteed that all exceptions thrown will share a particular common
> ancestor and type. 

Right, there are a couple of parts of the PEP that were
non-controversial from the start and would likely have happened even in
the absence of the PEP.

My point was that a lot of machinery is being thrown at a tiny problem.
To eliminate the need for "except (KeyError, SystemExit):  raise", we're
rearranging the tree, introducing a new builtin, banning an existing and
popular form of an except clause, and introducing a non-trivial
deprecation that will affect most users.  This is a lot of firepower
directed at a somewhat small problem.



> But no syntax will work in BOTH 2.5 and 3.0. 

There's the rub.  If you can't write code that will work for both, then
there is no reason to force 2.x users to make any changes to their
existing code, especially given that they won't see any benefit from the
mass edits.



> If we cannot produce a warning for these, then I'd
> rather not produce the warning for the use of bare "except:".
> After all, as it's been pointed out, if the use of bare "except:"
> is all you are interested in it is quite easy to grep the code to
> find all uses.

Bingo.  A bare except clause is well known as a consenting adults
construct.  If Guido feels driven to eliminate it from Py3.0, then that
is the way it is.  But for 2.x, why introduce unnecessary pain.

Of course, if bare except clauses weren't banned for 3.0, then we would
have no problem writing code that works on all versions on Python from
2.0 to 3.0, that doen't break existing code, and that doesn't invalidate
the text in Python books.  IMO, that is a nice situation.  Just how
badly do you want to kill bare except clauses.

I propose that leave them alone, and be happy that in 3.0 we can write
"except Exception" and get what we want without any fuss.



Raymond



More information about the Python-Dev mailing list