code: def text_if_str(
      to_type: Callable[..., T], text_or_primitive: Union[bytes, int, str]
  ) -> T:
      
      if isinstance(text_or_primitive, str):
          return to_type(text=text_or_primitive)
      else:
          return to_type(text_or_primitive)
docs: Convert to a type, assuming that strings can be only unicode text (not a hexstr)
  
      :param to_type function: takes the arguments (primitive, hexstr=hexstr, text=text),
          eg~ to_bytes, to_text, to_hex, to_int, etc
      :param text_or_primitive bytes, str, int: value to convert