[Python-bugs-list] [Bug #124106] isinstance() doesn't *quite* work on ExtensionClasses

noreply@sourceforge.net noreply@sourceforge.net
Mon, 4 Dec 2000 07:50:09 -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 : nascheme
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.

-------------------------------------------------------

Date: 2000-Dec-01 17:32
By: nascheme

Comment:
Just to be clear, that's not quite what I said.  This bug should be
fixed as part of the coerce cleanups.  I hope we can remove most of
the cases in the interpreter where PyInstances are treated specially.
I'm speculating that this would allow this bug to be easily fixed as
well as opening the door for any type to be use as a base class.
-------------------------------------------------------

Date: 2000-Dec-04 07:50
By: nascheme

Comment:
Fixed by patch #102630.
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=124106&group_id=5470