U
    kufZ  ã                   @  s2   d dl mZ d dlmZmZ ddddœdd„ZdS )é    )Úannotations)ÚAnyÚDictzDict[Any, Any])ÚthisÚthatÚreturnc                 C  s€   |   ¡ D ]P\}}t|tƒrD||krXt|| tƒrXt| | || ƒ q||kr|| | |< q|  ¡ D ]\}}|| krb|| |< qb| S )aò  Merge two nested dictionaries.

    Effectively a recursive ``dict.update``.

    Examples
    --------
    Merge two flat dictionaries:
    >>> nested_update(
    ...     {'a': 1, 'b': 2},
    ...     {'b': 3, 'c': 4}
    ... )
    {'a': 1, 'b': 3, 'c': 4}

    Merge two nested dictionaries:
    >>> nested_update(
    ...     {'x': {'a': 1, 'b': 2}, 'y': 5, 'z': 6},
    ...     {'x': {'b': 3, 'c': 4}, 'z': 7, '0': 8},
    ... )
    {'x': {'a': 1, 'b': 3, 'c': 4}, 'y': 5, 'z': 7, '0': 8}

    )ÚitemsÚ
isinstanceÚdictÚnested_update)r   r   ÚkeyÚvalue© r   úA/tmp/pip-unpacked-wheel-utpcgctl/traitlets/utils/nested_update.pyr      s    

r   N)Ú
__future__r   Útypingr   r   r   r   r   r   r   Ú<module>   s   