[Zope-Coders] ZopeVersionControl
Shane Hathaway
shane@zope.com
Fri, 21 Feb 2003 10:51:52 -0500
Florent Guillaume wrote:
> I was reading the diff for that change
> (http://cvs.zope.org/Products/ZopeVersionControl/ZopeRepository.py.diff?r1=1.2&r2=1.3),
> and Shane wrote:
>
> try:
> v = isinstance(object, ObjectManager)
> except TypeError:
> # Python 2.1 isinstance() dislikes ExtensionClass instances.
> # This is an adequate workaround.
> v = 0
>
> As I depend on this in some of my code, I'm wondering, in what case does
> this fail? I haven't found one:
In Python 2.1, if the second argument to isinstance() is an
ExtensionClass, it raises a TypeError instead of returning false. (In
all the cases you tested, isinstance() returned true.)
[shane@shane python]$ python2.1
Python 2.1.3 (#1, Apr 9 2002, 10:20:47)
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.63.1mdk)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> from ExtensionClass import Base
>>> class foo(Base):
... pass
...
>>> class c:
... pass
...
>>> isinstance(foo(), Base)
1
>>> isinstance(c(), Base)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: isinstance() arg 2 must be a class or type
Shane