python-dev Summary for 2004-02-01 through 2004-02-29

John Roth newsgroups at jhrothjr.com
Wed Mar 17 16:01:03 EST 2004


"Rocco Moretti" <roccomoretti at hotpop.com> wrote in message
news:c3a966$jqj$1 at news.doit.wisc.edu...
> Brett C. wrote:
>
> > ---------------------------------------------------
> > Do we really need mutability for exceptions groups?
> > ---------------------------------------------------
> > The question was raised as to why ``except (TypeError, ValueError):``
> > is acceptable while ``except [TypeError, ValueError]:`` (in other
> > words why use tuples to group exceptions for an 'except' statement and
> > not allow lists).  The question was in relation as to whether it had
> > something to do with a tuple's immutability.
> >
> > Guido said it all had to do with a visual way of grouping tuples and
> > nothing to do with what the underlying container was.  If he had it to
> > do over again he would rather change it so that ``except TypeError,
> > ValueError:`` did the same thing as above.  That change would
> > alleviate the common error of expecting the above behavior using that
> > syntax but instead getting the exception instance bound to ValueError.
> >  But the change is not planned for any time in the future since Guido
> > has no proposal on how to change the syntax to handle the assignment
> > to a local variable for the exception instance.
>
> Generalizing it to any iterable would be nice, especially with
> situations where you have the exception types stored in a variable:
>
> catch = (TypeError, ValueError, MyValueError)
> ...
> try:
>      #Body
> except catch:
>      #Error code
>
> If you need to dynamically add exceptions, it may be easier to use a
> list, and using general iterables opens up all sorts of fun with
> generators. (Is time savings all that big of deal here?)

Why would you need to dynamically add exceptions? My mind
is beginning to boggle trying to find a use case for this.


> As far as Python3000 syntax, has anyone suggested 'as' abuse?
>
> try:
>      #Body
> except TypeError, ValueError as e:
>      #Error code
>
> I'm not sure if this is compatable with the parser or not, but it looks
> nice ...

Well, since except is a statement, the parser shouldn't have a
problem with it. (except that as isn't a keyword - strange
exception, that.)

However, today it's only used in the import statement. If it
gets put into other statements, then it raises the question of
orthoganality.

John Roth
>
> -Rocco





More information about the Python-list mailing list