
    [e              	          d dl mZ d dlmZmZmZmZ d dlmZm	Z	 d dl
mZmZmZmZmZ  e	d          Z G d deeef         eeeef                   ZddZdS )    )annotations)CallableIterableIteratorMutableMapping)GenericTypeVar)KTVTZictBasecloseflushWTc                       e Zd ZU dZded<   ded<   ded<   d  fdZd!dZd"dZd#dZd$dZ	d%dZ
d&dZd'dZd(dZeZd)dZd)dZ xZS )*Funca  Buffer a MutableMapping with a pair of input/output functions

    Parameters
    ----------
    dump: callable
        Function to call on value as we set it into the mapping
    load: callable
        Function to call on value as we pull it from the mapping
    d: MutableMapping

    Examples
    --------
    >>> def double(x):
    ...     return x * 2

    >>> def halve(x):
    ...     return x / 2

    >>> d = {}
    >>> f = Func(double, halve, d)
    >>> f['x'] = 10
    >>> d
    {'x': 20}
    >>> f['x']
    10.0
    Callable[[VT], WT]dumpCallable[[WT], VT]loadMutableMapping[KT, WT]dc                r    t                                                       || _        || _        || _        d S N)super__init__r   r   r   )selfr   r   r   	__class__s       )lib/python3.11/site-packages/zict/func.pyr   zFunc.__init__+   s4     			    keyr
   returnr   c                B    |                      | j        |                   S r   )r   r   r   r    s     r   __getitem__zFunc.__getitem__6   s    yy%%%r   valueNonec                @    |                      |          | j        |<   d S r   )r   r   )r   r    r%   s      r   __setitem__zFunc.__setitem__9   s    ii&&sr   objectboolc                    || j         v S r   r   r#   s     r   __contains__zFunc.__contains__<   s    df}r   c                    | j         |= d S r   r,   r#   s     r   __delitem__zFunc.__delitem__?   s    F3KKKr   itemsIterable[tuple[KT, VT]]c                X      fd|D             } j                             |           d S )Nc              3  L   K   | ]\  }}|                     |          fV  d S r   )r   ).0kvr   s      r   	<genexpr>z"Func._do_update.<locals>.<genexpr>C   s6      22DAqq$))A,,222222r   )r   update)r   r0   its   `  r   
_do_updatezFunc._do_updateB   s6    2222E222br   Iterator[KT]c                *    t          | j                  S r   )iterr   r   s    r   __iter__zFunc.__iter__F   s    DF||r   intc                *    t          | j                  S r   )lenr   r>   s    r   __len__zFunc.__len__I   s    46{{r   strc                l    dt          | j                   dt          | j                   d| j         dS )Nz<Func: z<-> >)funcnamer   r   r   r>   s    r   __str__zFunc.__str__L   s9    P$),,PP$)1D1DPPtvPPPPr   c                .    t          | j                   d S r   )r   r   r>   s    r   r   z
Func.flushQ       dfr   c                .    t          | j                   d S r   )r   r   r>   s    r   r   z
Func.closeT   rK   r   )r   r   r   r   r   r   )r    r
   r!   r   )r    r
   r%   r   r!   r&   )r    r)   r!   r*   )r    r
   r!   r&   )r0   r1   r!   r&   )r!   r;   )r!   r@   )r!   rD   )r!   r&   )__name__
__module____qualname____doc____annotations__r   r$   r(   r-   r/   r:   r?   rC   rI   __repr__r   r   __classcell__)r   s   @r   r   r      sB         6 	 	 	 	 	 	& & & &' ' ' '               Q Q Q Q H          r   r   funcr   r!   rD   c                    t          | d          r| j        } t          | d          	 | j        S # t          $ r t	          |           cY S w xY w)zGet the name of a function.rT   )hasattrrT   rM   	ExceptionrD   )rT   s    r   rH   rH   X   si    
$

 y $

 }   4yys   0 AAN)rT   r   r!   rD   )
__future__r   collections.abcr   r   r   r   typingr   r	   zict.commonr
   r   r   r   r   r   r   rH    r   r   <module>r]      s    " " " " " " H H H H H H H H H H H H # # # # # # # # 6 6 6 6 6 6 6 6 6 6 6 6 6 6WT]]J J J J J8BFWRRZ0 J J JZ     r   