Is types.InstanceType no longer valid with Python 2.2

Hans Nowak wurmy at earthlink.net
Sat Jan 5 12:27:14 EST 2002


"Martin v. Loewis" wrote:
> 
> Skip Montanaro <skip at pobox.com> writes:
> 
> > How can foo be a classic class with no bases, f1 be both an instance of foo
> > and of object, but foo not be a subclass of object?
> 
> Would you agree that the following is sensible:
> 
> >>> class foo:pass
> ...
> >>> f=foo()
> >>> import types
> >>> isinstance(f,types.InstanceType)
> 1
> 
> f's type is <type 'instance'>, so f is an instance of InstanceType,
> just as isinstance(1, int). Now, would you also agree that
> 
> >>> types.InstanceType.__bases__
> (<type 'object'>,)
> 
> is meaningful, i.e. that object is a base of instance? (every type,
> eventually, has object as a base type)
> 
> If you accept both separately, you should also accept
> isinstance(f, object).

Python 2.2 is still sitting on my shelf, I don't have it installed,
and the recent discussions don't really make me want to. I don't
want to be a Python luddite, but all this messing around with
classes and types doesn't give me a good feeling, to say the
least.

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?

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.

I guess people may see me as one of those types who resist new
features in the language, but this really isn't the case. It's just
that I feel that these changes aren't very intuitive, and I'm putting
it mildly. Of course, everybody has to read the fine manual to 
understand a language's features completely and use them correctly,
and this is no different. Also, Guido & co are not dumb, and I'm
sure they made the right decisions. I just think that Python is 
moving away from its original qualities of being small, easy and 
intuitive.

Just my $0.02... let the flames begin... :-(

--Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==\n') 
       # decode for email address ;-)
Site:: http://www.awaretek.com/nowak/



More information about the Python-list mailing list