bug with isinstance() ?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Wed Jun 1 17:42:31 EDT 2005


Mac a écrit :
> Under certain circumstances isinstance() seems to return incorrect
> value for me.  I'm using Python 2.3 (latest from Debian's unstable).
> Here's a sample program... the multi-module nature of the code is key.
> 
> 
> === test.py ===
> 
> class Foo:
>     pass
> 
> def test():
>     from test2 import make_me_a_foo
>     foo = make_me_a_foo()
>     if isinstance(foo, Foo):
>         print "is a Foo"
>     else:
>         print "is  NOT  a Foo!"
> 
> if __name__ == "__main__":
>     test()
> 
> 
> === test2.py ===
> 
> from test import Foo
> 
> def make_me_a_foo():
>     return Foo()
> 
> 
> --8<--
> 
> When I run "python test.py", I get "is  NOT  a Foo!", when the object
> clearly IS a Foo!  Am I missing something, 

Yes

> or is this a bug?
Nope

try adding:
     print foo.__class__

after the second line of your test() function.




More information about the Python-list mailing list