title: Convert function arguments automatically from strings to datetimes
body: <p>I have a large collection of functions and methods that normally accept date/time objects. I want to adapt these to also accept string representations of a date/time objects.</p>
  
  <p>Consider the following function, which is a simple case</p>
  
  <pre><code>def days_until(until_date, from_date=None):
      if from_date is None:
          from_date = datetime.datetime.now()
      delta = until_date - from_date
      return delta.days
  </code></pre>
  
  <p><a href="https://stackoverflow.com/a/9517287/5747944">Using dateutil</a>, I would approach this by altering the function as follows.</p>
  
  <pre><code>def days_until(until_date, from_date=None):
      if isinstance(until_date, str): # preserve backwards compatibility with datetime objects
          until_date = dateutil.parser.parse(until_date)
      if isinstance(from_date, str):
          from_date = dateutil.parser.parse(from_date)
      # ... rest of function as it was before
  </code></pre>
  
  <p>While this works, the code is <strong>very repetitive</strong> and it is tedious to do across a large collection of functions, some of which accept as many as five datetimes.</p>
  
  <p>Is there an automatic/generic way to accomplish this conversion to achieve code that is DRY?</p>