from types import * class tc: def __init__(self, types=[]): self.types = types def _wrapper(self, func): def new_func(*args): if len(self.types)<>len(args): raise IndexError, 'Argument count mismatch' for i in range(len(args)): if type(args[i])<>self.types[i]: raise TypeError, 'Parameter type mismatch - paramater %s' % i return func(*args) return new_func def type_check(*types): checker = tc(types) return checker._wrapper @type_check(int, int) def test_int(a, b): print a + b @type_check(float, int) def test_float(a, b): print a + b #works test_int(1,2) #raises exception test(1.1, 2) #works test_float(1.1, 2)