import inspect


def _filter_module_all(path, root, children):
  """Filters module children based on the "__all__" arrtibute.

  Args:
    path: API to this symbol
    root: The object
    children: A list of (name, object) pairs.

  Returns:
    `children` filtered to respect __all__
  """
  del path
  if not (inspect.ismodule(root) and hasattr(root, '__all__')):
    return children
  module_all = set(root.__all__)
  children = [(name, value) for (name, value) in children if name in module_all]

  return children