Final tweaks:

- fix the __str__, __unicode__ and __repr__ methods
- some textual tweaks
- add Python 3.0 to the transition plan
This commit is contained in:
Guido van Rossum 2005-10-31 19:22:43 +00:00
parent 0fcf41f3cd
commit 3040eb4a06
1 changed files with 29 additions and 27 deletions

View File

@ -65,47 +65,46 @@ will cause the deprecation of the existing ``args`` attribute)::
def __init__(self, *args):
"""Set 'message' and 'args' attribute"""
self.args = args
self.message = args[0] if args else ''
self.args = args
self.message = args[0] if args else ''
def __str__(self):
"""Return the str of 'message'"""
return str(self.message
if not self.args
else self.args)
"""Return the str of 'message'"""
return str(self.message
if len(self.args) <= 1
else self.args)
def __unicode__(self):
"""Return the unicode of 'message'"""
return unicode(self.message
if not self.args
else self.args)
"""Return the unicode of 'message'"""
return unicode(self.message
if len(self.args) <= 1
else self.args)
def __repr__(self):
args_repr = (repr(self.message)
if not self.args
else "*%r" % self.args)
return "%s(%s)" % (self.__class__.__name__, args_repr)
if (len(self.args) <= 1):
return "%s(%r)" % (self.__class__.__name__, self.message)
return "%s%r" % (self.__class__.__name__, self.args)
def __getitem__(self, index):
"""Index into arguments passed in during instantiation.
Provided for backwards-compatibility and will be
deprecated.
Provided for backwards-compatibility and will be
deprecated.
"""
return self.args[index]
"""
return self.args[index]
The ``message`` attribute will contain either the argument passed in
at instantiation of the object or the empty string. The attribute is
meant to act as a common location to store any extra information that
is to be passed along with the exception that goes beyond the location
of the exception within the exception hierarchy and the exception's
type.
The ``message`` attribute will contain either the first argument
passed in at instantiation of the object or the empty string if no
arguments were passed in. The attribute is meant to act as a common
location to store any extra information that is to be passed along
with the exception that goes beyond the location of the exception
within the exception hierarchy and the exception's type.
No restriction is placed upon what may be passed in for ``messsage``.
This provides backwards-compatibility with how the argument passed
into Exception has no restrictions.
This provides backwards-compatibility with how the arguments passed
into Exception have no restrictions.
The ``args`` attribute is deprecated. While allowing multiple
arguments to be passed can be helpful, it is in no way essential. It
@ -214,11 +213,14 @@ specifically listed.
- deprecate catching exceptions that do not inherit from BaseException
* Python 2.9
- deprecate ``args`` and ``__getitem__``
* Python 3.0
- drop ``args`` and ``__getitem__``
References
==========