[Types-sig] optional typing and performance

jorendor@cbu.edu jorendor@cbu.edu
Thu, 03 Dec 1998 14:16:06 -0800


> The actual format for type declaration does not matter to me
>  as long as parser/compiler can recognize it.

Well, I'm going to throw my ear into the ring here..

I don't want to say ''' ''' every time I want to add type info.

According to what I've heard, Guido doesn't intend for Python 2.x
code to run under Python 1.x-- or indeed vice versa.  So "degrade
gracefully" isn't among the design criteria.

...

My preferred syntax looks more like C:

  def f(str text, int start):
      re.MatchObject match = _bi_re.search(text, start)
      if match is None:
          raise fError("not found")
      else:
          int end = match.end()
          return text[start:end]

The compiler should figure out the type info expressions
('str', 'int', 're.MatchObject') as soon as names have been bound.
If, for some reason, one of them can't be bound to a Type (Class?)
object at the moment, it can generate bytecode for a runtime check.

I don't like the idea of using ':' to delimit Python type info.
The colon is already used to mean a few other things.

The above is, IMHO, as readable as the rest of Python.  Anything
more goes into the verbose.

I think the builtins 'int', 'float', 'long' and 'str'
(and maybe 'tuple' and 'list') should become Class (Type?)
objects in Python2, so you can do this:

  if isinstance(x, str):  f(x, 0)

Well, I've rambled long enough.  I was working on some major
metaclassing revelations this morning, but my head exploded.

-- 
Jason