code: def _convert(value, to_type, default=None):
      
      try:
          return default if value is None else to_type(value)
      except ValueError:
          # If value could not be converted
          return default
docs: Convert value to to_type, returns default if fails.