__getattr__ possible loop
Gabriel Genellina
gagsl-py at yahoo.com.ar
Thu Dec 28 19:13:56 EST 2006
At Thursday 28/12/2006 14:01, Maksim Kasimov wrote:
> > Nothing so clever. dir() eats and ignores all exceptions, so when you
> > hit the recursion limit it eats the RecursionLimitExceeded exception
> > and continues merrily along the way. This is probably not good
> > behavior...
> >
> > class Foo:
> > def __getattr__(self, attr):
> > raise SystemExit, "Don't call me, again, ever"
> >
> > f = Foo()
> > f.method() #dies correctly
> > dir(f) #continues happily
>
>can't understand - what kind of problem you tried to fix in that way?
>if __getattr__ just raise some exception, it needless to define it at all.
The problem is, dir() blindly eats *all* exceptions, including the
RecursionLimitExceeded on the original post, this SystemExit,
KeyboardInterrupt, etc. It shouldn't.
Perhaps this example (esencially the same thing) is a bit more clear:
import sys
class Foo:
def __getattr__(self, attr):
print "About to exit program"
sys.exit(1)
f = Foo()
dir(f)
print "You should not see this line"
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
More information about the Python-list
mailing list