[Python-Dev] Proposed resolutions for open PEP 343 issues

Guido van Rossum guido at python.org
Wed Oct 26 00:05:25 CEST 2005

On 10/25/05, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Maybe there's a design principle in there somewhere:
>    Failed duck-typing -> AttributeError (or TypeError for complex checks)
>    Failed instance or subtype check -> TypeError

Doesn't convince me.

If there are principles at work here (and not just coincidences), they
are (a) don't  lightly replace an exception by another, and (b) don't
raise AttributeError; the getattr operation raise it for you. (a) says
that we should let the AttributeError bubble up in the case of the
with-statement; (b) explains why you see TypeError when a slot isn't

> Most of the functions in abstract.c handle complex protocols, so a simple
> attribute error wouldn't convey the necessary meaning. The context protocol,
> on the other hand, is fairly simple, and an AttributeError tells you
> everything you really need to know.

That's what I've been saying all the time. :-)

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

More information about the Python-Dev mailing list