code: def _format_contracts(what: str, obj: Any) -> List[str]:
      
      if what in ['function', 'method', 'attribute']:
          if what == 'attribute':
              if not isinstance(obj, property):
                  return []
  
              return _format_property_contracts(prop=obj)
  
          if what in ['function', 'method']:
              return _format_function_contracts(func=obj)
  
          raise NotImplementedError("Unhandled what: {}".format(what))
  
      elif what == 'class':
          invariants = getattr(obj, "__invariants__", [])  # type: List[icontract._Contract]
          assert isinstance(invariants, list)
          assert all(isinstance(inv, icontract._Contract) for inv in invariants)
  
          return _format_invariants(invariants=invariants)
  
      # Only properties, functions and classes have contracts.
      return []
docs: Format the contracts as reST.