New-style objects are not instances, apparently
arnodel at googlemail.com
Thu Jan 3 22:31:26 CET 2008
On Jan 3, 9:15 pm, "eef... at gmail.com" <eef... at gmail.com> wrote:
> I have a class that derives from Exception. In Python 2.4,
> isinstance(MyClass(), types.InstanceType) was True. In 2.5, it's
> Further experimentation showed that derivation from object was the
> culprit; new-style objects are not considered "instances" in the above
> sense. I wasn't able to figure out a workaround.
IIRC, this is because since 2.5 Exception is a new style class. New
style objects are instances of their class, not of InstanceType as was
the case with instances of old-style classes. So in your case
isinstance(MyClass(), Exception) will return True.
> Is there one, or is
> the distinction between traditional classes and built-in types only
> going to get more and more hazy?
I'm not sure what you mean here.
More information about the Python-list