Update the code for BaseException to have 'args' be more backwards-compatible.
Also reformat some methods to use the conditional operator to make the code simpler. Also moved the deprecation of 'args' and '__getitem__' to Python 2.9 so that it won't be removed during the 2.x series.
This commit is contained in:
parent
b7c609fd8d
commit
1070997d4f
31
pep-0352.txt
31
pep-0352.txt
|
@ -66,27 +66,26 @@ will cause the deprecation of the existing ``args`` attribute)::
|
|||
def __init__(self, message='', *args):
|
||||
"""Set 'message' and 'args' attribute"""
|
||||
self.message = message
|
||||
self.args = (message,) + args
|
||||
self.args = ((message,) + args
|
||||
if message != ''
|
||||
else tuple())
|
||||
|
||||
def __str__(self):
|
||||
"""Return the str of 'message'"""
|
||||
if len(self.args) > 1:
|
||||
return str(self.args)
|
||||
else:
|
||||
return str(self.message)
|
||||
return str(self.message
|
||||
if not self.args
|
||||
else self.args)
|
||||
|
||||
def __unicode__(self):
|
||||
"""Return the unicode of 'message'"""
|
||||
if len(self.args) > 1:
|
||||
return unicode(self.args)
|
||||
else:
|
||||
return unicode(self.message)
|
||||
return unicode(self.message
|
||||
if not self.args
|
||||
else self.args)
|
||||
|
||||
def __repr__(self):
|
||||
if len(self.args) > 1:
|
||||
args_repr = "*%s" % self.args
|
||||
else:
|
||||
args_repr = repr(self.message)
|
||||
args_repr = (repr(self.message)
|
||||
if not self.args
|
||||
else "*%r" % self.args)
|
||||
return "%s(%s)" % (self.__class__.__name__, args_repr)
|
||||
|
||||
def __getitem__(self, index):
|
||||
|
@ -190,7 +189,8 @@ is needed. The goal is to end up with the new semantics being used in
|
|||
Python 3.0 while providing a smooth transition for 2.x code. All
|
||||
deprecations mentioned in the plan will lead to the removal of the
|
||||
semantics starting in the version following the introduction of the
|
||||
deprecation.
|
||||
deprecation and the raising of a DeprecationWarning for the version
|
||||
specifically listed.
|
||||
|
||||
* Python 2.5
|
||||
|
||||
|
@ -216,6 +216,9 @@ deprecation.
|
|||
|
||||
- deprecate catching exceptions that do not inherit from BaseException
|
||||
|
||||
|
||||
* Python 2.9
|
||||
|
||||
- deprecate ``args`` and ``__getitem__``
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue