[ python-Bugs-965562 ] isinstance fails to recognize instance
SourceForge.net
noreply at sourceforge.net
Thu Jun 3 07:23:28 EDT 2004
Bugs item #965562, was opened at 2004-06-03 09:55
Message generated for change (Comment added) made by ijorgensen
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=965562&group_id=5470
Category: Python Interpreter Core
Group: Python 2.2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Ib Jørgensen (ijorgensen)
Assigned to: Nobody/Anonymous (nobody)
Summary: isinstance fails to recognize instance
Initial Comment:
I searched the bugbase and found a somewhat similar
problem that was termed invalid (id 563730 )
I did however spend some time figuring out what was
going wrong so..?
The following two modules document the problem:
MODULE A:
import b
class A:
def __init__(self):
self.name = "a"
if __name__ == "__main__":
x = A()
print "main",isinstance(x,A)
y = b.B()
y.notify(x)
MODULE B:
import a
class B:
def __init__(self):
self.name = "b"
def notify(self,cl):
print "notify",isinstance(cl,a.A)
if __name__ == "__main__":
x = a.A()
print isinstance(x,a.A)
y = B()
y.notify(x)
running module A gives inconsistent results
the printout is:
main True
notify False
The modules do have circular imports and it is clear that
this is behind the problem - but that may happen in real
life.
----------------------------------------------------------------------
>Comment By: Ib Jørgensen (ijorgensen)
Date: 2004-06-03 13:23
Message:
Logged In: YES
user_id=1055299
I have no problems if you close this bug. I do however feel
that it is quite subtle to distinguish classes by the rather
random import order.
----------------------------------------------------------------------
Comment By: Walter Dörwald (doerwalter)
Date: 2004-06-03 12:43
Message:
Logged In: YES
user_id=89016
The problem is not the circular import per se, but the fact
that module a gets imported twice, once as the __main__
module (with it's version of the class A) and once as the
module A (with it's own version of the class A).
>From Python's point of view these are two completely
unrelated classes with on inheritance relationship whatsoever.
Can this bug be closed?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=965562&group_id=5470
More information about the Python-bugs-list
mailing list