isinstance() bug

John Roth newsgroups at jhrothjr.com
Wed Jan 28 11:10:48 EST 2004


"Michal Vitecek" <fuf at mageo.cz> wrote in message
news:mailman.925.1075304492.12720.python-list at python.org...
> Skip Montanaro wrote:
> >You imported the module twice (look at sys.modules) so you have two
> >different A classes.  I believe isinstance() uses the __class__ attribute
> >and the class's __bases__ attribute to work its way up the class chain
> >looking for a match.  Even though they are defined identically, you have
two
> >different A classes.  An instance of one can't also be an instance of the
> >other.
>
>  i think that if absolute path was somehow put into the classes internal
>  information this inconsistency would be put away.
>
>  it's my belief that if i'm instantiating a class from the same location
>  no matter how i imported its definition, its instances are always of
>  the same class.
>
>  and as to the sys.modules thing: this could be considered as just two
>  references to the same module (again its absolute path would be taken
>  into account), not two different modules.
>
>  does it make sense?

It depends on the operating system. I think it's quite possible to
resolve the absolute path on, for example, Windows, while it's
not possible in the general case on, for example, Unix. If you have
two different paths hard linked to the same file, which one is the
"correct" path? It gets even worse if you're accessing the file from
a file server where you may not have the least idea what the aliasing
policies are.

The best advice I have is the same advice I give to anyone
who burns themselves doing something that doesn't work quite
the way they expect: don't do that. Imports need to be considered
thoughtfully.

John Roth
>
> -- 
> fuf (fuf at mageo.cz)
>





More information about the Python-list mailing list