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:
parent
61b759c5f7
commit
ad251f7c86
41
pep-0352.txt
41
pep-0352.txt
|
@ -59,8 +59,12 @@ will cause the deprecation of the existing ``args`` attribute)::
|
||||||
|
|
||||||
"""Superclass representing the base of the exception hierarchy.
|
"""Superclass representing the base of the exception hierarchy.
|
||||||
|
|
||||||
Provides a 'message' attribute that contains any argument
|
Provides a 'message' attribute that contains any single argument
|
||||||
passed in during instantiation.
|
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
|
The 'args' attribute and __getitem__ method are provided for
|
||||||
backwards-compatibility and will be deprecated at some point.
|
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):
|
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.args = args
|
||||||
self.message = args[0] if args else ''
|
self.message = args[0] if args else ''
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Return the str of 'message'"""
|
"""Return the str of args[0] or args, depending on length.
|
||||||
return str(self.message
|
|
||||||
|
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
|
if len(self.args) <= 1
|
||||||
else self.args)
|
else self.args)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
"""Return the unicode of 'message'"""
|
"""Return the unicode of args[0] or args, depending on length.
|
||||||
return unicode(self.message
|
|
||||||
|
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
|
if len(self.args) <= 1
|
||||||
else self.args)
|
else self.args)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if not self.args:
|
func_args = repr(self.args) if self.args else "()"
|
||||||
argss = "()"
|
return self.__class__.__name__ + func_args
|
||||||
else:
|
|
||||||
argss = repr(self.args)
|
|
||||||
return self.__class__.__name__ + argss
|
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
"""Index into arguments passed in during instantiation.
|
"""Index into arguments passed in during instantiation.
|
||||||
|
|
Loading…
Reference in New Issue