def check_list_type(objects, allowed_type, name, allow_none=True):
  """Verify that objects in list are of the allowed type or raise TypeError.

  Args:
    objects: The list of objects to check.
    allowed_type: The allowed type of items in 'settings'.
    name: Name of the list of objects, added to the exception.
    allow_none: If set, None is also allowed.

  Raises:
    TypeError: if object is not of the allowed type.

  Returns:
    The list of objects, for convenient use in assignment.
  """
  if objects is None:
    if not allow_none:
      raise TypeError('%s is None, which is not allowed.' % name)
    return objects
  if not isinstance(objects, (tuple, list)):
    raise TypeError('%s is not a list.' % name)
  if not all(isinstance(i, allowed_type) for i in objects):
    type_list = sorted(list(set(type(obj) for obj in objects)))
    raise TypeError('%s contains types that don\'t match %s: %s' %
                    (name, allowed_type.__name__, type_list))
  return objects
def check_list_type ( objects , allowed_type , name , allow_none = True ) : if objects is None : if not allow_none : raise TypeError ( '%s is None, which is not allowed.' % name ) return objects if not isinstance ( objects , ( tuple , list ) ) : raise TypeError ( '%s is not a list.' % name ) if not all ( isinstance ( i , allowed_type ) for i in objects ) : type_list = sorted ( list ( set ( type ( obj ) for obj in objects ) ) ) raise TypeError ( '%s contains types that don\'t match %s: %s' % ( name , allowed_type . __name__ , type_list ) ) return objects
Verify that objects in list are of the allowed type or raise TypeError.

  Args:
    objects: The list of objects to check.
    allowed_type: The allowed type of items in 'settings'.
    name: Name of the list of objects, added to the exception.
    allow_none: If set, None is also allowed.

  Raises:
    TypeError: if object is not of the allowed type.

  Returns:
    The list of objects, for convenient use in assignment.