[Python-3000] exception-swallowing behaviour of hasattr

Chris Mellon arkanes at gmail.com
Tue Jan 22 18:39:25 CET 2008


On Jan 22, 2008 11:36 AM, Guido van Rossum <guido at python.org> wrote:
>
> On Jan 22, 2008 9:31 AM, Chris Mellon <arkanes at gmail.com> wrote:
> > On Jan 22, 2008 9:36 AM, Guido van Rossum <guido at python.org> wrote:
> > > IMO (1) or (2) are both acceptable, but I'd prefer (2): swallow
> > > 'Exception'. There's a reason why hasattr() is different from
> > > getattr() with a default value; it's too early for me to explain it
> > > clearly, but I know it was discussed and argued at length when
> > > hasattr() was introduced.
> > >
> > > I don't see why AssertionError ought to be treated differently than
> > > TypeError or any other "regular" error. The key goal here is to avoid
> > > swallowing KeyboardInterrupt, and to a lesser extend SystemExit.
> > >
> > > --Guido
> > >
> >
> > A particularly nasty case is that it swallows RecursionLimitExceededError.
>
> Why is that nastier than other bugs?
>
>

Because when you mess up your hooks and end up with recursion through
hasattr, you get a hang followed by a segfault instead of an
exception. MemoryError might have similar effects.

(And of course I meant RuntimeError, not whatever thing I said)


More information about the Python-3000 mailing list