
    /_i/                    Z    d Z ddlmZ ddlmZmZ erddlmZ d	dZ	 d
	 	 	 	 	 ddZ	ddZ
y)zTools for working with dicts.    )annotations)TYPE_CHECKINGAny)Mappingc                    i }| j                         D ]9  \  }}|j                  d      }d}|}|D ]  }||vri ||<   |}||   } |5||<   ; |S )a  Convert a flat dict of key-value pairs to dict tree.

    Example
    -------

        _unflatten_single_dict({
          foo_bar_baz: 123,
          foo_bar_biz: 456,
          x_bonks: 'hi',
        })

        # Returns:
        # {
        #   foo: {
        #     bar: {
        #       baz: 123,
        #       biz: 456,
        #     },
        #   },
        #   x: {
        #     bonks: 'hi'
        #   }
        # }

    Parameters
    ----------
    flat_dict : dict
        A one-level dict where keys are fully-qualified paths separated by
        underscores.

    Returns
    -------
    dict
        A tree made of dicts inside of dicts.

    _N)itemssplit)	flat_dictoutpathstrvpath	prev_dict	curr_dictks           _/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/elements/lib/dicttools.py_unflatten_single_dictr      s    J Coo' 
}}S!+/		 	%A	!!	!!I!!I		%  IaL J    Nc                |   |
t               }t        |       }t        |j                               D ]  \  }}t	        |t
              rt        ||      }n?t        |d      r3t        |      D ]%  \  }}t	        |t
              st        ||      ||<   ' ||v sgd|vri |d<   ||d   |<   |j                  |        |S )a!  Converts a flat dict of key-value pairs to a spec tree.

    Example
    -------
        unflatten({
          foo_bar_baz: 123,
          foo_bar_biz: 456,
          x_bonks: 'hi',
        }, ['x'])

        # Returns:
        # {
        #   foo: {
        #     bar: {
        #       baz: 123,
        #       biz: 456,
        #     },
        #   },
        #   encoding: {  # This gets added automatically
        #     x: {
        #       bonks: 'hi'
        #     }
        #   }
        # }

    Args
    ----
    flat_dict: dict
        A flat dict where keys are fully-qualified paths separated by
        underscores.

    encodings: set
        Key names that should be automatically moved into the 'encoding' key.

    Returns
    -------
    A tree made of dicts inside of dicts.
    __iter__encoding)
setr   listr	   
isinstancedict	unflattenhasattr	enumeratepop)r   	encodingsout_dictr   r   ichilds          r   r   r   Q   s    R E	%i0HX^^%& 1a!Y'AQ
#%aL 75eT*$UI6AaD7
 	>)')$&'HZ #LLO  Or   c                    i }| j                         D ](  \  }}|	t        |t              rt        |      n|||<   * |S )z-Remove all keys with None values from a dict.)r	   r   r   remove_none_values)
input_dictnew_dictkeyvals       r   r&   r&      sL    H$$& VS?7A#t7L.s3RUHSMV Or   )r   dict[Any, Any]returnr+   )N)r   r+   r!   zset[str] | Noner,   r+   )r'   zMapping[Any, Any]r,   r+   )__doc__
__future__r   typingr   r   collections.abcr   r   r   r&    r   r   <module>r2      sE    $ " %'5r =A>>*9>>Br   