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

Eric Nieuwland eric.nieuwland at xs4all.nl
Tue Oct 25 22:05:18 CEST 2005

Guido van Rossum wrote:
> It is true though that AttributeError is somewhat special. There are
> lots of places (perhaps too many?) where an operation is defined using
> something like "if the object has attribute __foo__, use it, otherwise
> use some other approach".  Some operations explicitly check for
> AttributeError in their attribute check, and let a different exception
> bubble up the stack. Presumably this is done so that a bug in
> somebody's __getattr__ implementation doesn't get masked by the
> "otherwise use some other approach" branch. But this is relatively
> rare; most calls to PyObject_GetAttr just clear the error if they have
> a different approach available. In any case, I don't see any of this
> as supporting the position that TypeError is somehow more appropriate.
> An AttributeError complaining about a missing __enter__, __exit__ or
> __context__ method sounds just fine. (Oh, and please don't go checking
> for the existence of __exit__ before calling __enter__. That kind of
> bug is found with even the most cursory testing.)

Hmmm... Would it be reasonable to introduce a ProtocolError exception?


More information about the Python-Dev mailing list