Python Type-Inference based LINT.. (pylint.py)

Skip Montanaro skip at mojam.com
Thu Dec 2 17:27:34 EST 1999


    >> It isn't clear what syntax to use to specify an annotation

    def frobnicate(x as int,
                   y as [string],
                   z as {(int,int):SomeClass}) as SomeOtherClass:

Looks interesting.  I suggest two small changes:

    1. Use the names from the types module to save having to declare a bunch
       of new keywords (which would probably not pass Guido's scrutiny):

        from types import *
	...
	def frobnicate(x as IntType,
		       y as [StringType],
		       z as {(IntType,IntType):SomeClass}) as SomeOtherClass:

       If that's not acceptable, then perhaps enclosing the type specifiers
       in quotes would do the trick:

	def frobnicate(x as "int",
		       y as "[string]",
		       z as "{(int,int):SomeClass}") as "SomeOtherClass":

    2. I'd add a few meta types that correspond to the API behaviors (e.g.,
       "number", "sequence", "mapping", ...).  That would allow the type
       inferencer to make assumptions about the behavior of an argument
       without the programmer enumerating all the possible objects that
       could fill the bill.  These fake types could be added to the types
       module and set equal to None.  All you'd really be interested in is
       the names anyway (I think).

	def frobnicate(x as IntType,
		       y as SequenceType,
		       z as {(IntType,IntType):SomeClass}) as SomeOtherClass:

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
847-971-7098   | Python: Programming the way Guido indented...






More information about the Python-list mailing list