Movatterモバイル変換
[0]ホーム
[Python-Dev] Bare except clauses in PEP 348
Raymond Hettingerraymond.hettinger at verizon.net
Thu Aug 25 19:28:15 CEST 2005
> > Also, as we learned with apply(), even if> > ignored, the deprecation machinery has a tremendous runtime cost.None> > of this will make upgrading to Py2.5 an attractive option.>> Not in this case; bare except: can be flagged by the parser so the> warning happens only once per compilation.That's good news. It mitigates runtime cost completely.> > There is a reason that over 120 bare except clauses remain in the> > standard library despite a number of attempts to get rid of them.>> I betcha almost all of then can safely be replaced with "except> Exception".Because the tree is not being re-arranged until 3.0, those cases shouldalso introduce a preceding: except (KeyboardInterrupt, SystemExit): raiseAnywhere that doesn't apply will need: except BaseException: . . .and also some corresponding backwards compatibility code to work witholder pythons.If any are expected to work with user or third-party modules, then theycannot safely ignore string exceptions and exceptions not derived fromException. Each of those changes needs to be accompanied by test cases so that allcode paths get exercised.After the change, we should run Zope, Twisted, Gadfly, etc to make sureno major application got broken. Long running apps should verify thattheir recover and restart routines haven't been compromised. This isdoubly true if the invariant for a bare except was being relied upon asa security measure (this may or may not be a real issue).> But how about the following compromise: make it a silent deprecation> in 2.5, and a full deprecation in 2.6.I'd love to compromise but it's your language. If you're going todeprecate, just do it. Pulling the band-aid off slowly doesn't lessenthe total pain.My preference is of course, to leave 2.x alone and make this part of theattraction to 3.0. Remember, none of the code changes buys us anythingin 2.x. It is an exercise without payoff.My even stronger preference is to leave bare excepts in for Py3.0. Thatbuys us a happy world where code old code continues to work and new codecan be written that functions as intended on all pythons new and old.I'm no fan of bare exceptions, but I'm not inclined to shoot myself inthe foot to be rid of them. I wish Fredrik would chime in. He wouldhave something pithy, angry, and incisive to say about this.Raymond
More information about the Python-Devmailing list
[8]ページ先頭