[Python-3000] exceptions with keyword arguments

Guido van Rossum guido at python.org
Fri May 19 06:26:31 CEST 2006


On 5/18/06, Josiah Carlson <jcarlson at uci.edu> wrote:
>
> "tomer filiba" <tomerfiliba at gmail.com> wrote:
> > On 5/17/06, Brett Cannon <brett at python.org> wrote:
> > > And I brought this up with Guido once and he was not enthusiastic
> > > about it.  Basically, keep exceptions simple.  They are important
> > > and basic enough to keep it simple.  If you want fancier support,
> > > subclass Exception and add the support you want.
> >
> > well, if guido pronounced on it than i guess it's settled, but why do you
> > condsider *args to be simple and **kwargs not as simple? don't you
> > think "ex.filename" is simpler/clearer than "ex[1]"?
>
> From what I understand of Brett's post, ex[1] won't be available anymore
> either.

Correct.

> While it would be convenient for inspecting exceptions when they are
> caught via ex.attr, creating exceptions with keyword arguments seems
> like it would be a bit if a pain.

All this has little to do with exceptions per se. It's just about
classes, subclasses, constructor signatures, and instance attributes.

There's no need for the attributes to match the keywords, nor is there
a need to access values using x[i] notation when they were passed to
the constructor sequentially.

BaseException (in py3k) defines one positional argument and one
attribute named message.

Some standard exceptions will provide more attributes (e.g. errno,
filename, strerror etc.) and ways to provide values for those via the
constructor. It's up to each subclass of BaseException to define the
appropriate costructor signature.

(Is this perhaps yet another case of the misunderstanding that the
constructor signature of a subclass must be compatible with that of
the base class? Assuming single inheritance there's no need for that
restriction.)

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


More information about the Python-3000 mailing list