def typecheck(types, ranges=None):

    def __f(f):

        def _f(*args, **kwargs):
            for a, t in zip(args, types):
                if not isinstance(a, t):
                    raise ValueError('Expected %s got %r' % (t, a))
for a, r in zip(args, ranges or []):
    if r and not r[0] <= a <= r[1]:
        raise ValueError('Should be in range %r: %r' % (r, a))
return f(*args, **kwargs)
return _f
return __f
Python — проверка параметров с повышением исключения