[Types-sig] Type annotation progress

Paul Prescod paulp@ActiveState.com
Sun, 18 Mar 2001 23:46:19 -0800


I've now got a proper grammar for type declarations. I also have the
ability to allow out-of-line declarations so that I can annotate the
standard library without actually editing the files. For your interest,
here is a declaration file for "sre" (also known as "re").

I have a script that compiles these declarations into the .pyc
associated with a module. SRE passes all test cases after this process
and yet gives proper error checks when misused:

python -c "import sre; print sre.match(None, 'foo')
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "c:\python20\lib\sre.py", line 43, in match
    def match(pattern, string, flags=0):
typecheck.InterfaceError: Parameter 'pattern' expected Unicode or 8-bit
string.
Instead it got 'None' (None)

==========================
__declare__("""
def compile(pattern: IString, flags: IInt) -> compiled_re: IRegex

def match(pattern: IString, string: IString,  flags: IInt) 
                    -> match : (IMatch | INone)

def search(pattern: IString, string: IString, flags: IInt)
                    -> match : (IMatch | INone)

def split(pattern: IString, string: IString, maxsplit: IInt)
                    -> ISequence

def findall(pattern: IString, string: IString) -> ISequence

def sub(pattern: IString, 
        repl: (IString|ICallable),
        string: IString, count: IInt) -> IString

def subn(pattern: IString, repl: IString, count: IInt) 
                -> (new_string: IString, number_of_subs_made: IInt)

def escape(pattern: IString) -> escaped_string: IString
""")

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook