from typing import NamedTuple


def _to_dict(conf: NamedTuple):
    """Convert nested named tuple to dict."""
    d = conf._asdict()
    for k in conf._fields:
        el = getattr(conf, k)
        if hasattr(el, '_asdict'):
            d[k] = _to_dict(el)
    return d