[Python-Dev] RE: PEP-317

Aahz aahz@pythoncraft.com
Tue, 10 Jun 2003 10:23:02 -0400


On Tue, Jun 10, 2003, Guido van Rossum wrote:
>
> But I'm not at all happy with the proposed deprecation of
> 
>   raise Class
> and
>   raise Class, arguments
> 
> in favor of
> 
>   raise Class()
> and
>   raise Class(arguments)
> 
> I don't see how this change is necessary in order to get any of the
> other benefits.

Yeah.  I've been thinking a bit, and while the proposed change makes
some sense for the case where you're passing an argument to an
exception, it makes this look uglier:

class Found(Exception):
    pass

try:
    for record in records:
        for field in record.fields:
            if data in field.data:
                raise Found()
except Found:
    # handle success
else:
    # handle failure

I find that extra set of parentheses unnecessary and ugly.  It implies a
callable where it's not really being used that way, particularly in the
asymmetry between the ``raise`` and the ``except``.  If this change goes
through, I might start doing

class Found(Exception):
    pass
Found = Found()
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra