Tweak and accept PEP 352 -- new exception hierarchy.

This commit is contained in:
Guido van Rossum 2006-02-10 19:48:38 +00:00
parent a7f168262d
commit e927bc15de
2 changed files with 30 additions and 17 deletions

View File

@ -68,6 +68,7 @@ Index by Category
SA 308 Conditional Expressions GvR, Hettinger
SA 328 Imports: Multi-Line and Absolute/Relative Aahz
SA 343 The "with" Statement GvR, Coghlan
SA 352 Required Superclass for Exceptions GvR, Cannon
Open PEPs (under consideration)
@ -105,7 +106,6 @@ Index by Category
S 345 Metadata for Python Software Packages 1.2 Jones
I 350 Codetags Elliott
S 351 The freeze protocol Warsaw
S 352 Required Superclass for Exceptions GvR, Cannon
S 353 Using ssize_t as the index type von Loewis
S 354 Enumerations in Python Finney
S 355 Path - Object oriented filesystem paths Lindqvist
@ -404,7 +404,7 @@ Numerical Index
SD 349 Allow str() to return unicode strings Schemenauer
I 350 Codetags Elliott
S 351 The freeze protocol Warsaw
S 352 Required Superclass for Exceptions GvR, Cannon
SA 352 Required Superclass for Exceptions GvR, Cannon
S 353 Using ssize_t as the index type von Loewis
S 354 Enumerations in Python Finney
S 355 Path - Object oriented filesystem paths Lindqvist

View File

@ -3,7 +3,7 @@ Title: Required Superclass for Exceptions
Version: $Revision$
Last-Modified: $Date$
Author: Brett Cannon <brett@python.org>, Guido van Rossum <guido@python.org>
Status: Draft
Status: Accepted
Type: Standards Track
Content-Type: text/x-rst
Created: 27-Oct-2005
@ -34,12 +34,15 @@ Introducing a new superclass for exceptions also gives us the chance
to rearrange the exception hierarchy slightly for the better. As it
currently stands, all exceptions in the built-in namespace inherit
from Exception. This is a problem since this includes two exceptions
(KeyboardInterrupt and SystemExit) that are usually meant to signal
that the interpreter should be shut down. Changing it so that these
two exceptions inherit from the common superclass instead of Exception
will make it easy for people to write ``except`` clauses that are not
overreaching and not catch exceptions that should propagate up and
terminate the interpreter.
(KeyboardInterrupt and SystemExit) that often need to be excepted from
the application's exception handling: the default behavior of shutting
the interpreter down with resp. without a traceback is usually more
desirable than whatever the application might do (with the possible
exception of applications that emulate Python's interactive command
loop with ``>>>`` prompt). Changing it so that these two exceptions
inherit from the common superclass instead of Exception will make it
easy for people to write ``except`` clauses that are not overreaching
and not catch exceptions that should propagate up.
This PEP is based on previous work done for PEP 348 [#pep348]_.
@ -81,9 +84,13 @@ will cause the deprecation of the existing ``args`` attribute)::
else self.args)
def __repr__(self):
if (len(self.args) <= 1):
return "%s(%r)" % (self.__class__.__name__, self.message)
return "%s%r" % (self.__class__.__name__, self.args)
if not self.args:
argss = "()"
elif len(self.args) <= 1:
argss = "(%s)" % repr(self.message)
else:
argss = repr(self.args)
return self.__class__.__name__ + argss
def __getitem__(self, index):
"""Index into arguments passed in during instantiation.
@ -201,12 +208,12 @@ desired.
* Python 2.5
- allow exceptions to be new-style classes
- all standard exceptions become new-style classes
- introduce BaseException
+ allow exceptions to be new-style classes
+ all standard exceptions become new-style classes
- Exception, KeyboardInterrupt, and SystemExit inherit from BaseException
- deprecate raising string exceptions
@ -229,7 +236,13 @@ desired.
* Python 3.0
- drop ``args`` and ``__getitem__``
- drop everything that was deprecated above:
+ drop string exceptions (could do this sooner?)
+ all exceptions must inherit from BaseException
+ drop ``args`` and ``__getitem__``
Implementation