Convert a list of command arguments to types specified by the handler.

    Args:
      handler: a command handler function.
      args: the list of string arguments to pass to handler.

    Returns:
      A new list containing `args` that have been converted to the expected type
      for `handler`. For each function parameter of `handler` that has either an
      explicit type annotation or a non-None default value, the corresponding
      element in `args` is converted to that type.

def _convert_args(handler, args):
    """Convert a list of command arguments to types specified by the handler.

    Args:
      handler: a command handler function.
      args: the list of string arguments to pass to handler.

    Returns:
      A new list containing `args` that have been converted to the expected type
      for `handler`. For each function parameter of `handler` that has either an
      explicit type annotation or a non-None default value, the corresponding
      element in `args` is converted to that type.
    """

    args = list(args)
    params = inspect.signature(handler).parameters
    for i, (arg, name) in enumerate(zip(args, params)):
        default = params[name].default
        annotation = params[name].annotation

        if annotation != inspect.Parameter.empty:
            if isinstance(annotation, type) and annotation != str:
                # The parameter is annotated with a type that isn't str: convert
                # the arg to that type.
                args[i] = annotation(arg)
        elif default != inspect.Parameter.empty:
            if default is not None and not isinstance(default, str):
                # The parameter has a default value that isn't None or a str:
                # convert the arg to the default value's type.
                args[i] = type(default)(arg)

    return args