[Python-Dev] PEP 352: Required Superclass for Exceptions

Nick Coghlan ncoghlan at gmail.com
Fri Oct 28 13:12:42 CEST 2005

Brett Cannon wrote:
> Anyway, as soon as the cron job posts the PEP to the web site (already
> checked into the new svn repository) have a read and start expounding
> about how wonderful it is and that there is no qualms with it
> whatsoever.  =)

You mean aside from the implementation of __getitem__ being broken in 
BaseException*? ;)

Aside from that, I actually do have one real problem and one observation.

The problem: The value of ex.args

   The PEP as written significantly changes the semantics of ex.args - instead 
of being an empty tuple when no arguments are provided, it is instead a 
singleton tuple containing the empty string.

   A backwards compatible definition of BaseException.__init__ would be:

     def __init__(self, *args):
         self.args = args
         self.message = '' if not args else args[0]

The observation: The value of ex.message

   Under PEP 352 the concept of allowing "return x" to be used in a generator 
to mean "raise StopIteration(x)" would actually align quite well. A bare 
"return", however, would need to be changed to translate to "raise 
StopIteration(None)" rather than its current "raise StopIteration" in order to 
get the correct value (None) into ex.message.


* (self.args[0] is self.message) due to the way __init__ is written, but 
__getitem__ assumes self.message isn't in self.args)

Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list