Recipe of the week: Decorator for checking method signatures

by Jeremy Jones

I'm not a huge advocate of getting type checking into Python, but this is an interesting recipe. By applying a decorator, you can specify what types the input and output of a function/method should be. I like having the flexibility to be able to do this if I want to. (As an aside, one benefit for me of working with code that has explicit input and return types is knowing for certain what type of thing a method/function takes.)

The recipe can be found here. It's not revolutionary and may be less relevant when signature annotations make it into Python 3000, but it's really interesting to look at now. (Less relevant meaning in the immediate knowledge of what types something takes and returns by reading it in a Python 3000 signature-annotated method. I know that there aren't plans for typechecking in py3k.)