type-checking support in Python?

Kay Schluehr kay.schluehr at gmx.net
Mon Oct 13 09:39:49 CEST 2008


On 6 Okt., 16:19, Joe Strout <j... at strout.net> wrote:
> I'm just re-learning Python after nearly a decade away.  I've learned  
> a good healthy paranoia about my code in that time, and so one thing  
> I'd like to add to my Python habits is a way to both (a) make intended  
> types clear to the human reader of the code, in a uniform manner; and  
> (b) catch any type errors as early and automatically as possible.
>
> I found the "typecheck" module (http://oakwinter.com/code/typecheck/),  
> but I notice that it hasn't been updated since 2006, and it's not  
> included with the Python distribution.  Are there other modules  
> providing similar functionality that I should consider instead?

Incidentally I started to use the typecheck package just yesterday.
It's not that I'm using it in a typical application but I'm working on
a mapping of a statically typed language onto a Python framework that
emerges in parallel. So I have to rebuild the type semantics of the
original language in Python but defer typechecks until runtime.

My impressions so far have been mixed. I stumbled across some strange
failures that required uncommenting source code in the typecheck
package which might cause failures elsewhere. I also hit a barrier
when working with methods instead of functions. I also noticed that
passing two strings to a funtcion:

@accepts(Number, Number)
def add(x,y):
    return x+y

is acceptable behaviour.

>From all those experiences I'd rate the package alpha and I'm sad
noticing that it is apparently abandonware. I'll continue to use it
nevertheless.



More information about the Python-list mailing list