Is types.InstanceType no longer valid with Python 2.2

Martin v. Loewis martin at v.loewis.de
Sun Jan 6 15:17:52 EST 2002


Hans Nowak <wurmy at earthlink.net> writes:

> To stay on the subject, one would *think* that if isinstance(f, object)
> is true, then issubclass(foo, object) would be true too. This does
> not seem to be the case. It take it that custom (or "classic") class
> definitions do not automagically and implicitly inherit from object.
> But types do. This strikes me as odd. I thought the changes were
> supposed to mend the class/type dichotomy, not to make it more
> difficult. Because there's nothing mended: now you have objects that
> derive from object, and those that don't. Or was this decision made
> to ensure backward compatibility?

Exactly. Code that uses classic classes will continue to work as it
did before. Types offer more functionality than before: you can define
them using the class construct, and you can inherit from them, both in
C an Python. Several things that people always expected to work do work
now, e.g. "hello".__class__.

I don't see a problem with the isinstance call: Since isinstance(x,
object) yields 1 for any x, nobody would want to do this except to
understand it better.

Of course, it is now more difficult than it was before to tell apart
instances of old-style classes from other objects - that result is
expected if the class/type dichotomy is mended.

> Before 2.0, Python used to have a reputation of being small
> and easy to learn. I don't know what happened to it, but ever
> since, new features of dubious utility have been piling up, and I
> don't think the new type/class rules can be called "easy", either.

There were always things that had been surprising. It is not different
now; it is still easy to learn. To learn means to ignore.

> I just think that Python is moving away from its original qualities
> of being small, easy and intuitive.

It is still easy and intuitive. If, by "small", you are referring to
the syntax, it is still small also: the new-style classes did not add
a single syntax construct to the language. If you refer to the
library: It stopped being small in release 1.2 or so, and many people
consider this a good thing. So far, the new-style classes are just
extension to the library: types have additional features that they did
not have before. You can use them or you can leave them.

Regards,
Martin




More information about the Python-list mailing list