[Types-sig] Return of the Docstring: The Typening

Evan Simpson evan@4-am.com
Thu, 16 Dec 1999 16:25:26 -0600


I'm sure this was bandied around in the (distant) past, but since
backward-compatible inline syntaxes are being proposed, I thought I'd
resurrect it:
Put the type constraints (of whatever syntax) in docstrings (and ignored
strings).  Shadow files for extensions can simply be .pyt's with dummy
objects definitions, or could be more compact.  Example:

def foo(x1, x2):
    '''A foo function
    ::(int, int) -> int'''
    return x1+x2

'bar:: string'; bar = "I'm a string!"

class Mine:
    '''My class! Mine!
    hm, uh:: float'''
    hm = 1.0
    uh = 3.14

This could also serve as a shadow file, or perhaps a more compact
notation:

def foo::(int, int) ->int

bar:: string

class Mine:
    hm, uh:: float

That is, if we're going to have name-type declarations at all.  I'm
rather partial to expression-type constraints with 'as' instead of '!'.
Perform single-module analysis at compile time (if requested) to produce
a type-inference graph such as Tim(?) described.  Save the graph in a
*.pyt file, then have a tool which uses them to do full-program
type-checking, and possibly rewrite the *.pyc if optimization is
possible and requested.

I still like the Sparrow/SPython concept, too <wink>.

Cheers,

Evan @ 4-am