code: def get_formatted_as_type(self, value, default=None, out_type=str):
          
          if value is None:
              value = default
  
          if isinstance(value, SpecialTagDirective):
              result = value.get_value(self)
              return types.cast_to_type(result, out_type)
          if isinstance(value, str):
              result = self.get_formatted_string(value)
              result_type = type(result)
              if out_type is result_type:
                  # get_formatted_string result is already a string
                  return result
              elif out_type is bool and result_type is str:
                  # casting a str to bool is always True, hence special case. If
                  # the str value is 'False'/'false', presumably user can
                  # reasonably expect a bool False response.
                  return result.lower() in ['true', '1', '1.0']
              else:
                  return out_type(result)
          else:
              return out_type(value)
docs: Return formatted value for input value, returns as out_type.
  
          Caveat emptor: if out_type is bool and value a string,
          return will be True if str is 'True'. It will be False for all other
          cases.
  
          Args:
              value: the value to format
              default: if value is None, set to this
              out_type: cast return as this type
  
          Returns:
              Formatted value of type out_type