[Python-ideas] Specificity in AttributeError

Ethan Furman ethan at stoneleaf.us
Sat Apr 27 09:39:29 CEST 2013


On 04/26/2013 11:59 PM, Devin Jeanpierre wrote:
> On Sat, Apr 27, 2013 at 1:49 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
>
> Discovering that there is a bug is one thing, discovering why is
> another. The problems that result from silently doing the wrong thing
> can be significantly harder to diagnose than an exception traceback
> is, and this hasattr_lite would let me get an exception in cases where
> I might otherwise have silently wrong behavior.
>
> I mean, yes, this error was in fact found in my unit test suite. I
> spent a lot of time tracking it down (perhaps too much time, because I
> was expecting something else [oops, too many changes in one changeset
> :X]), and eventually narrowed it down to a try/except
> AttributeError I had. Even then, trying to filter out the legitimate
> AttributeErrors and the illegitimate one from the same test case was
> annoying. I ended up breaking at the except block and individually
> examining the exceptions, both legitimate and not. This solved
> everything.
>
> hasattr_lite (if it worked) would've reported the problem as an
> AttributeError, with exactly the typo I had made in an attribute name
> inside a property. Seconds to figure out and fix.
>
> So what I mean is, it isn't necessary, but I would find it helpful and
> convenient.

I absolutely agree, and would like to see the available info on other exceptions (KeyError, IndexError, etc.) as well. 
I suspect it would take some serious effort to upgrade all the exceptions from all the places they can be raised from, 
though.

--
~Ethan~



More information about the Python-ideas mailing list