[Python-bugs-list] [Bug #124106] isinstance() doesn't *quite* work on ExtensionClasses
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 1 Dec 2000 17:23:25 -0800
Bug #124106, was updated on 2000-Dec-01 17:21
Here is a current snapshot of the bug.
Project: Python
Category: Core
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: gward
Assigned to : Nobody
Summary: isinstance() doesn't *quite* work on ExtensionClasses
Details: In 1.6, isinstance() and issubclass() were generalized so they work on ExtensionClass instances and classes as well as vanilla Python instances and classes... almost. Unfortunately, it doesn't work in one case:
isinstance(inst, ECClass)
where inst is a vanilla Python instance and ECClass an ExtensionClass-derived class raises TypeError with the message "second argument must be a class".
Neil says this should work with his PyInstance_Check() patch, so I'm going to assign this one to him.
Follow-Ups:
Date: 2000-Dec-01 17:23
By: gward
Comment:
Oops, forgot to include this script that demonstrates the bug:
"""
from ExtensionClass import ExtensionClass, Base
class SuperEC (Base):
pass
class ChildEC (SuperEC):
pass
class Super:
pass
class Child (Super):
pass
def test(cond):
print cond and "ok" or "not ok"
c1 = Child()
c2 = ChildEC()
test(issubclass(Child, Super))
test(issubclass(ChildEC, SuperEC))
test(isinstance(c1, Child))
test(isinstance(c1, Super))
test(not isinstance(c2, Child))
test(isinstance(c2, ChildEC))
test(isinstance(c2, SuperEC))
test(not isinstance(c1, ChildEC))
test(not isinstance(c1, SuperEC))
"""
When I run this, I get the following output:
"""
ok
ok
ok
ok
ok
ok
ok
Traceback (most recent call last):
File "ectest", line 30, in ?
test(not isinstance(c1, ChildEC))
TypeError: second argument must be a class
"""
Output is the same with Python 1.6 and 2.0.
-------------------------------------------------------
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=124106&group_id=5470