What's a simple utility function to differentiate between an old-style and a new-style python class or object?
Are the following correct/complete:
isNewStyle1 = lambda o: isinstance(hasattr(o, '__class__') and o.__class__ or o, type)
isNewStyle2 = lambda o: hasattr(o, '__class__') and type(o) == o.__class__ or False
If not, then can you provide a solution. If so, is there a nicer way to do the check?
Using the above, I've not had any problems, but I don't have 100% confidence that it will work for all objects supplied as parameters.
Why not just
True
for new style classes,False
for classic classesYou can support classes with different metaclasses like this (so long as the metaclass is subclassing type)