Makes validator for function to ensure it takes nargs args.

def _nargs_validator(nargs, message):
  """Makes validator for function to ensure it takes nargs args."""
  if message is None:
    message = "Registered function must take exactly %d arguments" % nargs

  def f(key, value):
    del key
    spec = inspect.getfullargspec(value)
    if (len(spec.args) != nargs or spec.varargs is not None or
        spec.varkw is not None):
      raise ValueError(message)

  return f