Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] Bare except clauses in PEP 348

Raymond Hettingerraymond.hettinger at verizon.net
Thu Aug 25 11:35:31 CEST 2005


> > OK, I'm convinced. Let's drop bare except for Python 3.0, and> > deprecate them until then, without changing the meaning.> >>> WoohooThat's no cause for celebration.  Efforts to improve Py3.0 have spilledover into breaking Py2.x code with no compensating benefits.  Bareexcept clauses appear in almost every Python book that has ever beenwritten and occur at least once in most major Python applications.I had thought the plan was to introduce Py3.0 capabilities into 2.x asthey become possible but not to break anything.  Isn't that why stringexceptions, buffer(), and repr() still live and breathe?We don't have to wreck 2.x in order to make 3.0 better.  I wish the 3.0PEPs would stop until we are actually working on the project and havesome chance of making people's lives better.  If people avoid 2.5 justto avert unnecessary breakage, then Py3.0 doesn't benefit at all.I propose that the transition plan be as simple as introducingBaseException.  This allows people to write code that will work on both2.x and 3.0.  It doesn't break anything.  The guidance for cross-version (2.5 to 3.0) code would be:* To catch all but terminating exceptions, write:    except (KeyError, SystemExit):        raise    except Exception:                       ...* To catch all exceptions, write:    except BaseException:                   ...To make the code also run on 2.4 and prior, add transition code:    try:        BaseException    except NameError:        class BaseException(Exception):            passWith that minimal guidance, people can write code that works on from 2.0to 3.0 and not break anything that is currently working.  Nodeprecations are necessary.Remember, the ONLY benefit from the whole PEP is that in 3.0, it will nolonger be necessary to write "except (KeyError, SystemExit):  raise".Steven and Jack's research show that that doesn't arise much in practiceanyway.  IOW, there's nothing worth inflicting destruction on tons of2.x code.Raymond


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp