The following usage of isinstance doesn't seem to work in Python 2.5.2 or 2.6.2:
class BananaCake:
def __init__(self):
print 'Banana Cake'
class ChocolateCake:
def __init__(self):
print 'Chocolate Cake'
class CakeFactory:
@staticmethod
def create(name):
if name == 'banana':
return BananaCake
elif name == 'chocolate':
return ChocolateCake
else:
return None
if __name__ == '__main__':
banana_cake = CakeFactory.create('banana')
print isinstance(banana_cake, BananaCake)
The above isinstance is returning False even though banana_cake is an instance of BananaCake. Does anyone know what I might be missing? I'm performing this check in my test scripts. You should be able to copy and paste the above and run it easily in a Python script.