from typing import Mapping


def asdict(i, argname: str):
    """
    Converts iterables-of-pairs or just a pair-tuple into a dict.

    :param argname:
        Used in the exception raised when `i` not an iterable.
    """
    if not i:
        return i if isinstance(i, dict) else {}

    if isinstance(i, tuple) and len(i) == 2:
        i = dict([i])
    elif not isinstance(i, Mapping):
        try:
            i = dict(i)
        except Exception as ex:
            raise ValueError(f"Cannot dict-ize {argname}({i!r}) due to: {ex}") from None

    return i