code: def coerce_to_datetime(x: Any) -> Optional[datetime.datetime]:
      
      if x is None:
          return None
      elif isinstance(x, DateTime):
          return pendulum_to_datetime(x)
      elif isinstance(x, datetime.datetime):
          return x
      elif isinstance(x, datetime.date):
          return datetime.datetime(x.year, x.month, x.day)
      else:
          return dateutil.parser.parse(x)
docs: Ensure an object is a :class:`datetime.datetime`, or coerce to one, or
      raise :exc:`ValueError` or :exc:`OverflowError` (as per
      http://dateutil.readthedocs.org/en/latest/parser.html).