def parse_kwargs(s):
    """Parse command line arguments into Python arguments for parsers.

    Converts an arguments string of the form: key1=value1,key2=value2 into
    a dict of arguments that can be passed to Python initializers.

    This function also understands type prefixes and will cast values prefixed
    with 'int:' or 'float:'. For example magic_number=int:4 will be converted
    to {"magic_number": 4}.

    """
    if s is None:
        return {}

    kwargs = {}
    for argument in s.split(","):
        key, value = argument.strip().split("=")

        if value.startswith("int:"):
            value = int(value[4:])

        elif value.startswith("float:"):
            value = float(value[6:])

        kwargs[key] = value

    return kwargs