Static typing

Bjorn Pettersen BPettersen at NAREX.com
Fri Jul 25 17:56:47 EDT 2003


> From: Shane Hathaway [mailto:shane at zope.com] 
> 
> Scott David Daniels wrote:
> > You _might_ want some static typing information as program
> > documentation or to enable efficient program translation.  The
> > types sig was interested in allowing type annotation where
> > possible.  Remember, the type you might want may be more like
> > "what protocol must these objects (the ones passing through
> > this variable) follow" than "what are the construction details
> > of these objects".
> > 
> > I would like to see interface descriptions describing what
> > kinds of parameters are required and results produced for
> > packages that I am considering using.  If there were a single
> > central-python-endorsed form for those descriptions even better.
> > If the descriptions can be mechanically read, and at least
> > sometimes mechincally checked (possibly slowly, possibly only
> > for slow execution), I might use such a system to check a module
> > before announcing it to the world.
> 
> Well, here's a pattern I've been trying out for this purpose: 
> use assert 
> statements at the top of the function.
> 
> def foo(bar, baz):
>      assert isinstance(bar, int)
>      assert isinstance(baz, str)
[...]

...which means you can't use foo with unicode strings or UserStrings,
etc., etc. This is C programming in Python, ugly, inefficient,
inflexible, and un-Pythonic.

-- bjorn





More information about the Python-list mailing list