Re: Thoughts and proposals about types and classes

Jaap Vermeulen (jaap@sequent.com)
Fri, 10 Sep 93 09:48:00 PDT

| def oldstyle(x):
| if type(x) in (type(()), type([])):
| for i in range(len(x)):
| print i, x[i]
| else:
| print x

What about:

def altstyle(x)
try:
for i in range(len(x)):
print i, x[i]
except TypeError:
print x

Here you would rely on the fact that len(x) would return TypeError on an
unsized object. Or, the x[i] would return TypeError on an unsubscriptable
object.

Either way, if Python would move towards a more pure OO paradigm, the
subscription would become a method and you should be able the turn the
allowed() into a simple check whether a method exists.

This brings to another point from the previous discussion with Steven. In
most cases when you decide to forego on the type checking, you will run into
either a TypeError or an AttributeError if the wrong object was passed in
(as Jack points out). In a more pure OO environment with a perfect
namespace, you would refer to a method that doesn't exist for that object
(given the wrong object was passed in).

Disclaimer: With a "pure OO paradigm" I refer to an environment solely based
on method lookup.

-Jaap-