Rework pseduo-code to better match implementation. Only affected __str__ and

__unicode__.  Had to be done this way for backwards-compatibility issues.
This commit is contained in:
Brett Cannon 2006-03-01 23:44:47 +00:00
parent 61b759c5f7
commit ad251f7c86
1 changed files with 29 additions and 12 deletions

View File

@ -59,8 +59,12 @@ will cause the deprecation of the existing ``args`` attribute)::
"""Superclass representing the base of the exception hierarchy.
Provides a 'message' attribute that contains any argument
passed in during instantiation.
Provides a 'message' attribute that contains any single argument
passed in during instantiation. If more than one argument is passed, it
is set to the empty string. It is meant to represent any message
(usually some text) that should be printed out with the traceback.
Unfortunatley, for backwards-compatibility, the 'args' attribute
(discussed below) is used for printing out to tracebacks.
The 'args' attribute and __getitem__ method are provided for
backwards-compatibility and will be deprecated at some point.
@ -68,28 +72,41 @@ will cause the deprecation of the existing ``args`` attribute)::
"""
def __init__(self, *args):
"""Set 'message' and 'args' attribute"""
"""Set 'message' and 'args' attribute.
'args' will eventually be deprecated. But it is still used when
printing out tracebacks for backwards-compatibility. Once 'args' is
removed, though, 'message' will be used instead.
"""
self.args = args
self.message = args[0] if args else ''
def __str__(self):
"""Return the str of 'message'"""
return str(self.message
"""Return the str of args[0] or args, depending on length.
Once 'args' has been removed, 'message' will be used exclusively for
the str representation for exceptions.
"""
return str(self.args[0]
if len(self.args) <= 1
else self.args)
def __unicode__(self):
"""Return the unicode of 'message'"""
return unicode(self.message
"""Return the unicode of args[0] or args, depending on length.
Once 'args' has been removed, 'message' will be used exclusively for
the unicode representation of exceptions.
"""
return unicode(self.args[0]
if len(self.args) <= 1
else self.args)
def __repr__(self):
if not self.args:
argss = "()"
else:
argss = repr(self.args)
return self.__class__.__name__ + argss
func_args = repr(self.args) if self.args else "()"
return self.__class__.__name__ + func_args
def __getitem__(self, index):
"""Index into arguments passed in during instantiation.