from typing import Dict


def parse_arg(api_name: str, s: str) -> Dict[str, str]:
    """parse an argument in following formats:
    1. typename name
    2. typename name = default_value
    """
    typename, rest = [item.strip() for item in s.split(" ", 1)]
    assert len(
        typename
    ) > 0, f"The arg typename should not be empty. Please check the args of {api_name} in yaml."

    assert rest.count(
        "=") <= 1, f"There is more than 1 = in an arg in {api_name}"
    if rest.count("=") == 1:
        name, default_value = [item.strip() for item in rest.split("=", 1)]
        assert len(
            name
        ) > 0, f"The arg name should not be empty. Please check the args of {api_name} in yaml."
        assert len(
            default_value
        ) > 0, f"The default value should not be empty. Please check the args of {api_name} in yaml."
        return {
            "typename": typename,
            "name": name,
            "default_value": default_value
        }
    else:
        name = rest.strip()
        assert len(
            name
        ) > 0, f"The arg name should not be empty. Please check the args of {api_name} in yaml."
        return {"typename": typename, "name": name}