def _GetValidMain(module):
  """Returns a main function in module if it exists and is valid or None.

  A main function is valid if it can be called with no arguments, i.e. calling
  module.main() would be valid.

  Args:
    module: The module in which to search for a main function.

  Returns:
    A function that takes no arguments if found or None otherwise.
  """
  if not hasattr(module, 'main'):
    return None
  main = module.main
  if not hasattr(main, '__call__'):
    return None
  defaults = main.__defaults__
  if defaults:
    default_argcount = len(defaults)
  else:
    default_argcount = 0
  if (main.__code__.co_argcount - default_argcount) == 0:
    return main
  else:
    return None