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

Guido van Rossum guido at python.org
Sat Oct 29 05:22:36 CEST 2005

[Trying to cut this short... We have too many threads for this topic. :-( ]

On 10/28/05, Nick Coghlan <ncoghlan at gmail.com> wrote:
[on making args b/w compatible]
> I agree changing the behaviour is highly unlikely to cause any serious
> problems (mainly because anyone *caring* about the contents of args is rare),
> the current behaviour is relatively undocumented, and the PEP now proposes
> deprecating ex.args immediately, so Guido's well within his rights if he wants
> to change the behaviour.

I take it back. Since the feature will disappear in Python 3.0 and is
maintained only for b/w compatibility, we should keep it as b/w
compatible as possible. That means it should default to () and always
have as its value exactly the positional arguments that were passed.

OTOH, I want message to default to "", not to None (even though it
will be set to None if you explicitly pass None as the first
argument). So the constructor could be like this (until Python 3000):

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

I think Nick proposed this before as well, so let's just do this.

> I'm talking about the specific context of the behaviour of 'return' in
> generators, not on the behaviour of ex.message in general. For normal
> exceptions, I agree '' is the correct default.
> For that specific case of allowing a return value from generators, and using
> it as the message on the raised StopIteration, *then* it makes sense for
> "return" to translate to "raise StopIteration(None)", so that generators have
> the same 'default return value' as normal functions.

I don't like that (not-even-proposed) feature anyway. I see no use for
it; it only gets proposed by people who are irked by the requirement
that generators can contain 'return' but not 'return value'. I think
that irkedness is unwarranted; 'return' is useful to cause an early
exit, but generators don't have a return value so 'return value' is

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list