Re: static type checking / interface definitions for Python?

Guido.van.Rossum@cwi.nl
Fri, 23 Sep 1994 15:45:15 +0200

Bill Janssen:

> >> I'm wondering if anyone has done a design for optional static
> >> typing in Python?
> >>
> >> I'm thinking of this in several levels. (I'm not wedded to or even very
> >> enthusiastic about the syntax I suggest in this note.)

George Reynolds:

> We have actually just started thinking about this. The issue for us is
> generating C++ from python. The context would be a prototyping
> environment where at the end of prototyping exercise, one could
> generate C++ automatically, bind the resulting functions to python
> and gain the perfrmance advantage. To do this we need static typing.
>
> We are planning to do an internal (to VI) extension to the language
> which would be used in a prtotyping environment we would deliver
> with a product.
>
> However it would obviously be better if this were part of standard
> python.

Well there's an obvious solution: don't make it an proprietary
extension but instead start discussing its requirements, design and
implementation on the list. I'm more than happy to comment and I'm
sure there are quite a few others also interested. This really is the
only way to come to some kind of standardization of such an extension.

In reply to Bill: ABC (Python's most direct predecessor and influence)
has quite a nifty global static typechecking algorithm, deriving the
types of variables (and arguments, etc.) from the use that is made of
them. It can't be used without changes for Python because in ABC, the
items of a list must all have the same type: you can have a function
taking a list of X, where in one invocation X is "number" and in
another invocation X is "string", but you can never have a list whose
items are partly numbers and partly strings. Also, Python is a lot
more dynamic, if you consider things like exec, eval() and conditional
import. However, the ABC algorithm makes a good start, and what I
particularly like about it that it doesn't ever require you to declare
the type of a variable -- it's all derived from what's there already.

The URL "http://www.cwi.nl/~steven/abc.html" contains on-line
documentation for ABC as well as a full publication list. The report
"Incremental Polymorphic Type-Checking in B" listed in the subnode on
Publications contains a description of the aforementioned algorithm
("B" was ABC's old name).

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>