[Python-Dev] Evil isinstance()
Guido van Rossum
Mon, 01 Apr 2002 20:26:28 -0500
> [Guido van Rossum]
> > > This doesn't seem so much of a problem to me to warrant rejecting
> > > perfectly good numberlike and stringlike classes' instances, by
> > > isinstance'ing away.
> > Agreed, and I think the solution ought to be sought in asking a
> > question involving hasattr().
> Having recently removed most calls to hasattr() from PyCrust's
> introspection routines, I'd be curious to get more of your opinion
> on this issue. Specifically, I removed calls to hasattr() because
> xmlrpclib always returns true for hasattr(), rendering it
> effectively meaningless.
Hm. I didn't know xmlrpc did that, and I think it's pretty unique in
this respect. It looks like a hack, and one that can only work as
long as attributes on xmlrpc instances are always supposed to be
methods. Why didn't you choose to special-case xmlrpc? It appears
that introspecting an xmlrpc instance is hopeless anyway...
(Depending on what you need the introspection for, of course. You
haven't told us the whole story.)
It's true, you can't trust hasattr() 100%. In fact, there's no way to
determine with 100% accuracy whether an object has a particular
attribute or not. But that doesn't mean you can't make an educated
--Guido van Rossum (home page: http://www.python.org/~guido/)