def _construct_optional(params):
    """Construct optional args' key and abbreviated key from signature."""

    args = []
    filtered = {key: arg.default for key, arg in params.items() if arg.default != inspect._empty}
    for key, default in filtered.items():
        arg = OptionalArg(full=key, abbrev=key[0].lower(), default=default)
        args.append(arg)

    args_full, args_abbrev = dict(), dict()

    # Resolve conflicts
    known_count = defaultdict(int)
    for arg in args:
        args_full[arg.full] = arg

        if known_count[arg.abbrev] == 0:
            args_abbrev[arg.abbrev] = arg
        elif known_count[arg.abbrev] == 1:
            new_abbrev = arg.abbrev.upper()
            args_full[arg.full] = OptionalArg(full=arg.full, abbrev=new_abbrev, default=arg.default)
            args_abbrev[new_abbrev] = args_full[arg.full]
        else:
            new_abbrev = arg.abbrev.upper() + str(known_count[arg.abbrev])
            args_full[arg.full] = OptionalArg(full=arg.full, abbrev=new_abbrev, default=arg.default)
            args_abbrev[new_abbrev] = args_full[arg.full]
        known_count[arg.abbrev] += 1
    return args_full, args_abbrev
Construct optional args' key and abbreviated key from signature.