Adding static typing to Python

Nick Mathewson QnickQm at alum.mit.edu
Tue Feb 19 23:38:31 EST 2002


[message reformatted]

In article <24c39b2c.0202191658.3fd74528 at posting.google.com>, 
                    Alexander Jerusalem wrote:
> QnickQm at alum.mit.edu (Nick Mathewson) wrote in message 
>          news:<slrna74ssf.21s.QnickQm at localhost.localdomain>...
>> In article <24c39b2c.0202181531.187fad4c at posting.google.com>, 
>>         Alexander Jerusalem wrote:
>> > Has anyone heard of plans to add static type checking to Python?
>> 
>> Someone else has mentioned an old proposal of Guido's for adding
>> optional type declarations in order to help the compiler catch errors.
 
 [... an example that eventually arrives at a type like ...]

>> And you aren't using _all_ of the sequence protocol: just iteration...
>> 
>>      (A, B) -> str   s.t. A has __iter()__ -> C 
>>                      s.t. C has next() -> D (or raises StopIteration)
>>                      s.t. D has __eq__(B) and repr() -> str
>> 
>> IMNSHO, some kind type inference is the only tractable answer.
>> 
>> And-what-if-repr-doesn't-return-a-string?-ly yrs,
> 
> You argue that there are cases where static typing gets in your way,
> where it makes programs less flexible.

Well, not quite.  I argue that assigning types to even trivial Python
programs is a delicate and tricky business, and that the static types
implicit in a typical Python function are tremendously complex.

This _isn't_ an argument against optional static types for Python: I
believe in them too.  This is just an explanation of why they haven't
been done _yet_:
    1) Typical type declarations for Python will be more complex than
        those of most other popular languages.
    2) Therefore, type inference is almost certainly necessary.
    3) Because of 1 and 2, optional static typing for Python will 
        involve a lot of work. :)

Of course, this isn't to say that it won't or shouldn't get done: just
that the cost portion of the cost/benefit here is very high---and the
free time among the people who know enough about Python in particular
and type systems in general is quite low.

Of-course-I'd-love-to-be-proven-wrong-ly yrs,

-- 
 Nick Mathewson    <Q nick Q m at alum dot mit dot edu>
                      Remove Q's to respond.  No spam.



More information about the Python-list mailing list