from typing import Optional
from typing import Mapping
from typing import Any


def _set_dut(tb_params: Optional[Mapping[str, Any]], dut_lib: str, dut_cell: str
             ) -> Optional[Mapping[str, Any]]:
    """Returns a copy of the testbench parameters dictionary with DUT instantiated.

    This method updates the testbench parameters dictionary so that the DUT is instantiated
    statically in the inner-most wrapper.
    """
    if tb_params is None:
        return tb_params

    ans = {k: v for k, v in tb_params.items()}
    dut_params: Optional[Mapping[str, Any]] = tb_params.get('dut_params', None)
    if dut_params is None:
        ans['dut_lib'] = dut_lib
        ans['dut_cell'] = dut_cell
    else:
        ans['dut_params'] = _set_dut(dut_params, dut_lib, dut_cell)
    return ans