
    X-Ph=,                        d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZmZmZmZmZmZmZ erddlmZ ddZddZ G d d          ZdS )zLUtilities for mapping between actual and formal arguments (and their types).    )annotations)Sequence)TYPE_CHECKINGCallable)nodes)map_instance_to_supertype)
AnyTypeInstanceParamSpecType	TupleTypeTypeTypedDictType	TypeOfAnyTypeVarTupleType
UnpackTypeget_proper_type)ArgumentInferContextactual_kindslist[nodes.ArgKind]actual_namesSequence[str | None] | Noneformal_kindsformal_namesSequence[str | None]actual_arg_typeCallable[[int], Type]returnlist[list[int]]c                    t                    }d t          |          D             g }d}t                     D ]J\  }}	|	t          j        k    rs||k     rl|                                         s!|                             |           |dz  }W|         t          j        k    r|                             |           |	t          j        k    r
t           ||                    }
t          |
t                    r{t          t          |
j                            D ]W}||k     rO|         t          j        k    r|                             |           n n|         t          j        k    r|dz  }XB||k     rZ|                             d          rn=|                             |           |         t          j        k    rn|dz  }||k     Z|	                                r|
J d            ||         }|v rY                    |                   t          j        k    r0                    |                                       |           )t          j        v r8                    t          j                                               |           q|	t          j        k    sJ t           ||                    }
t          |
t                    r|
j        D ]{}|v r/                    |                                       |           5t          j        v r8                    t          j                                               |           |5|                    |           L|rC fdt          |          D             }|D ]"}|D ]}|                             |           #S )	a3  Calculate mapping between actual (caller) args and formals.

    The result contains a list of caller argument indexes mapping to each
    callee argument index, indexed by callee index.

    The caller_arg_type argument should evaluate to the type of the actual
    argument type with the given index.
    c                    g | ]}g S  r!   ).0is     K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/argmap.py
<listcomp>z*map_actuals_to_formals.<locals>.<listcomp>+   s    (E(E(E(E(E(E    r      T)starNz/Internal error: named kinds without names givenc                    g | ]b}|         r@|         r"|         d                   t           j        k    r|         t           j        k    s|         t           j        k    `|cS )r   )r   ARG_STAR	ARG_STAR2)r"   fir   r   r   formal_to_actuals     r$   r%   z*map_actuals_to_formals.<locals>.<listcomp>i   s     
 
 
R 	
 ),
 $$4R$8$;<NN $66B5?22  322r&   )lenrange	enumerater   ARG_POSis_starappendr*   r   
isinstancer   itemsr+   is_namedindexr   )r   r   r   r   r   nformalsambiguous_actual_kwargsr,   aiactual_kindactualt_nameunmatched_formalsr-   s   ` ``          @r$   map_actuals_to_formalsr@      s    <  H(E(EU8__(E(E(E)+	
B$\22 43 43K%-''H}}#B'//11 4$R(//333!GBB!"%77$R(//333EN**%oob&9&9::G'9-- s7=1122 $ $AH}}'+u>>,R077;;;;!E'+u~==!GB 8mm#B'00d0;; 8(,33B777#B'5>99!GB 8mm !!## 	3++-^+++#D|##\5G5G5M5M(NRWR`(`(` !3!3D!9!9:AA"EEEEL00 !3!3EO!D!DELLRPPP%/1111%oob&9&9::G'=11 
3#M Y YD|++(););D)A)ABII"MMMML88(););EO)L)LMTTUWXXX	Y (..r2222 0

 
 
 
 
 
 
Hoo
 
 
 * 	0 	0B' 0 0 $++B////0 r&   list[str | None]c                    t          | ||||          }d | D             }t          |          D ]%\  }}|D ]}	||	                             |           &|S )z8Calculate the reverse mapping of map_actuals_to_formals.c                    g | ]}g S r!   r!   )r"   r=   s     r$   r%   z*map_formals_to_actuals.<locals>.<listcomp>   s    (B(B(B(B(B(Br&   )r@   r0   r3   )
r   r   r   r   r   r-   actual_to_formalformalactualsactuals
             r$   map_formals_to_actualsrH   }   s     .lL,  )C(B\(B(B(B$%566 4 4 	4 	4FV$++F3333	4r&   c                  &    e Zd ZdZddZ	 dddZdS )ArgTypeExpandera  Utility class for mapping actual argument types to formal arguments.

    One of the main responsibilities is to expand caller tuple *args and TypedDict
    **kwargs, and to keep track of which tuple/TypedDict items have already been
    consumed.

    Example:

       def f(x: int, *args: str) -> None: ...
       f(*(1, 'x', 1.1))

    We'd call expand_actual_type three times:

      1. The first call would provide 'int' as the actual type of 'x' (from '1').
      2. The second call would provide 'str' as one of the actual types for '*args'.
      2. The third call would provide 'float' as one of the actual types for '*args'.

    A single instance can process all the arguments for a single call. Each call
    needs a separate instance since instances have per-call state.
    contextr   r   Nonec                H    d| _         t                      | _        || _        d S )Nr   )tuple_indexsetkwargs_usedrK   )selfrK   s     r$   __init__zArgTypeExpander.__init__   s!    %(UUr&   Factual_typer   r;   nodes.ArgKindformal_name
str | Noneformal_kindallow_unpackboolc                6   |}t          |          }|t          j        k    rt          |t                    rt          |j                  }t          |t                    rf|j        r_ddlm	}  ||| j
        j                  r*t          || j
        j        j                  j        d         S t          t          j                  S t          |t"                    r| j        t'          |j                  k    rd| _        n| xj        dz  c_        |j        | j        dz
           }t          |t*                    rv|stt          |j                  }	t          |	t                    rt          |	j                  }
n|	}
t          |
t                    r|
j        j        dk    sJ |
j        d         }|S t          |t.                    r|S t          t          j                  S |t          j        k    r%ddlm	} t          |t2                    r|t          j        k    r||j        v r|J n@t5          |j                                                  | j        z
                                  }| j                            |           |j        |         S t          |t                    r@ ||| j
        j                  r*t          || j
        j        j                  j        d         S t          |t.                    r|S t          t          j                  S |S )a  Return the actual (caller) type(s) of a formal argument with the given kinds.

        If the actual argument is a tuple *args, return the next individual tuple item that
        maps to the formal arg.

        If the actual argument is a TypedDict **kwargs, return the next matching typed dict
        value type based on formal argument name and kind.

        This is supposed to be called for each formal, in order. Call multiple times per
        formal if multiple actuals map to a formal.
        r   )
is_subtyper'   zbuiltins.tuple) r   r   r*   r4   r   upper_boundr
   argsmypy.subtypesr[   rK   iterable_typer   typer	   r   
from_errorr   rN   r.   r5   r   fullnamer   r+   r   rO   keysrP   popaddmapping_type)rQ   rS   r;   rU   rW   rX   original_actualr[   itemunpackedfallbacks              r$   expand_actual_typez"ArgTypeExpander.expand_actual_type   s   & &%k22%.((+'788 G .k.EFF+x00 &5[5E &5444444:k4<+EFF 	94#T\%?%D 1  #9#7888K33 5#s;+<'='==='(D$$$$)$$"()9A)=>dJ// , ,.ty99H!(,<== ,#283G#H#H#+"8X66$M26FFFFF#=+DK77 5""y3444EO++000000+}55 5%/11k[EV6V6V&2222 $'{'8'='='?'?#@#@4CS#S"X"X"Z"ZK $$[111"(55K22 5zzT\68 8 5
 1dl>W>\]]b  K77 5""y3444 #"r&   N)rK   r   r   rL   )F)rS   r   r;   rT   rU   rV   rW   rT   rX   rY   r   r   )__name__
__module____qualname____doc__rR   rk   r!   r&   r$   rJ   rJ      sW         *    #]# ]# ]# ]# ]# ]# ]#r&   rJ   N)r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   rA   r   r   r   r   )ro   
__future__r   collections.abcr   typingr   r   mypyr   mypy.maptyper   
mypy.typesr	   r
   r   r   r   r   r   r   r   r   
mypy.inferr   r@   rH   rJ   r!   r&   r$   <module>rw      sh   R R " " " " " " $ $ $ $ $ $ * * * * * * * *       2 2 2 2 2 2                         0//////_ _ _ _D   &{# {# {# {# {# {# {# {# {# {#r&   